0

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.

2 Answers 2

1

Try

curl -i -F filename=image.jpg -F image=@/path/to/image.jpg http://localhost/xmlcreate/curlupload.php
Sign up to request clarification or add additional context in comments.

3 Comments

I got this as output:HTTP/1.1 100 Continue HTTP/1.1 200 OK Date: Tue, 04 Nov 2014 13:01:49 GMT Server: Apache/2.2.22 (Ubuntu) X-Powered-By: PHP/5.3.10-1ubuntu3.13 Vary: Accept-Encoding Content-Length: 0 Content-Type: text/html
Was the file uploaded? Since your script doesn't output anything, it's hard to say if it worked or not!
I tried the same with server connected to the same network.. But it didn't upload it to that server. what else should I do?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.