2

i want to write a script which post a form automatically. it is not a spammer! there is a picture field in form. i want to write the script with php and using curl() function. how can i implement file uploading? and is the php suitable for this purpose? i mean form posting?

1 Answer 1

4

To upload a file that's on your server, yes, curl can do the trick.

You'll want to use the CURLOPT_POSTFIELDS option, passing it to the curl_setopt function (quoting) :

The full data to post in a HTTP "POST" operation.
To post a file, prepend a filename with @ and use the full path.


Not tested, but I suppose that something like this should work :
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.yoursite.com/destination-of-upload.php");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setpopt($ch, CURLOPT_POSTFIELDS, array(
        'file' => '@/..../some-file.txt',    // you'll need to adapt this
        // some other fields ?
));
$result = curl_exec($ch);
curl_close($ch);
Sign up to request clarification or add additional context in comments.

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.