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?
+2
A:
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);
Pascal MARTIN
2010-04-12 17:45:49
thanks Pascal,i will try it.
hd
2010-04-12 20:56:35