Reputation: 341
I have to upload the file in my local system using the CURL HTTP POST in linux command line.
I have used these commands, with no success:
curl -F "image=@/var/www/fbapp/images/registration.png" http://localhost/xmlcreate/curlupload.php
curl --form "fileupload=@/var/www/fbapp/images/registration.png" http://localhost/xmlcreate/curlupload.php
curl -X POST -d @/var/www/fbapp/images/registration.png http://localhost/xmlcreate/curlupload.php
curl --data-binary @/var/www/fbapp/images/registration.png http://localhost/xmlcreate/curlupload.php
I used all these commands but none of these worked.
Here is my PHP file where I'm trying to get the uploaded file(using curl) and save it in some other directory:
<?php
$uploadpath = "images/";
$filedata = $_FILES['image']['tmp_name'];
$filename = $_POST['filename'];
if ($filedata != '' && $filename != '')
copy($filedata,$uploadpath.$filename);
?>
Can someone please help me with this. I'm stuck here and not able to go forward.
Once it starts working on the local I have to use the remote server URL, instead of the localhost.
Upvotes: 0
Views: 3206
Reputation: 4025
Try
curl -i -F filename=image.jpg -F image=@/path/to/image.jpg http://localhost/xmlcreate/curlupload.php
Upvotes: 1
Reputation: 146
Try using
move_uploaded_file()
I think at least one of your CURL commands work. To check simply put something like:
file_put_contents('log.txt',print_r($_FILES,true));
in your code and check what you get from curl in real time.
Upvotes: 0