luzu
luzu

Reputation: 3

Upload image to PHP server using cURL?

Using a very simple PHP server:

<?php
$file = date("YmdHisms") . ".jpg";
file_put_contents($file, file_get_contents("php://input"));
?>

I'm trying to upload images using cURL:

curl --data "/path/to/image.jpg" 'http://192.168.1.3'

or:

upload multiple files to php server using curl command line

curl -F "[email protected]" 'http://192.168.1.3'

or:

cat image.jpg | curl --data - 'http://192.168.1.3'

Files are getting created in my web sever directory, but the images don't seem to open? What am I getting wrong here?

Upvotes: 0

Views: 273

Answers (2)

Rinsad Ahmed
Rinsad Ahmed

Reputation: 1943

Change the php code to

<?php
   $file = date("YmdHisms") . ".jpg";
   move_uploaded_file($_FILES['image']['tmp_name'], $file);
?>

Upvotes: 1

K F
K F

Reputation: 1546

Try this:

curl -i -X POST -H "Content-Type: multipart/form-data" -F "[email protected]" http://192.168.1.3

Upvotes: 0

Related Questions