cURL Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TS_Death_Angel
Forum Commoner
Posts: 31
Joined: Sat Dec 31, 2005 8:49 am

cURL Help

Post 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.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Could you post some code? There's probably something wrong with your cURL code... the syntax is a bit obtuse.
TS_Death_Angel
Forum Commoner
Posts: 31
Joined: Sat Dec 31, 2005 8:49 am

Post 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;
?>
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post 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.
TS_Death_Angel
Forum Commoner
Posts: 31
Joined: Sat Dec 31, 2005 8:49 am

Post 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?
TS_Death_Angel
Forum Commoner
Posts: 31
Joined: Sat Dec 31, 2005 8:49 am

Post by TS_Death_Angel »

No one knows? :(
Post Reply