Page 1 of 1

cURL Help

Posted: Sat Dec 31, 2005 8:52 am
by TS_Death_Angel
I'm trying to make a PHP script that will upload images to imageshack and return the thumbnails. I can do the second part, but the first part, all cURL returns is "1". Could anyone help me out with this? Imageshack is really weird.

Posted: Sat Dec 31, 2005 12:37 pm
by Ambush Commander
Could you post some code? There's probably something wrong with your cURL code... the syntax is a bit obtuse.

Posted: Sat Dec 31, 2005 2:56 pm
by TS_Death_Angel
Ambush Commander wrote:Could you post some code? There's probably something wrong with your cURL code... the syntax is a bit obtuse.
Got that right :( Here's what I've got so far:

Code: Select all

<?

$url = 'http://imageshack.us/index.php';

$postData = array();

$postData['fileupload'] = "@dire1.jpg";
$postData['submit'] = "UPLOAD";
$postData['MAX_FILE_SIZE'] = '3145728';
	  
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url );       
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_USERAGENT, $ua);


curl_setopt($ch, CURLOPT_POSTFIELDS, $postData );

$response = curl_exec( $ch );
echo $response;
?>

Posted: Sat Dec 31, 2005 3:10 pm
by Ambush Commander
You haven't matched ImageShack's form inputs precisely: you need to set the uploadtype. Otherwise, you seem to have followed the instructions perfectly... not really sure what's wrong. Also, try curl_error() and see if curl is returning an error. Also, you can try removing CURLOPT_RETURNTRANSFER and see if anything is returned: if something is, use output buffering to catch it.

Posted: Sat Dec 31, 2005 3:39 pm
by Ree
You definately have some POST fields missing. You can easily check all the POST fields using the 'View Page Info' in FF - it will tell you all the form fields on the page and their current values. Another thing I have noticed, is that you pass an array with CURLOPT_POSTFIELDS. It should be a string like this: var1=value1&var2=value2& ... . I am not sure, maybe it works with the array, but I doubt it.

Posted: Sat Dec 31, 2005 3:59 pm
by TS_Death_Angel
Ree wrote:You definately have some POST fields missing. You can easily check all the POST fields using the 'View Page Info' in FF - it will tell you all the form fields on the page and their current values. Another thing I have noticed, is that you pass an array with CURLOPT_POSTFIELDS. It should be a string like this: var1=value1&var2=value2& ... . I am not sure, maybe it works with the array, but I doubt it.
It does work with an array. I tried doing some of the stuff suggested, but now I'm getting server errors. Could someone else have a go?

Posted: Tue Jan 03, 2006 10:01 am
by TS_Death_Angel
No one knows? :(