cURL Help
Moderator: General Moderators
-
TS_Death_Angel
- Forum Commoner
- Posts: 31
- Joined: Sat Dec 31, 2005 8:49 am
cURL Help
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.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
-
TS_Death_Angel
- Forum Commoner
- Posts: 31
- Joined: Sat Dec 31, 2005 8:49 am
Got that rightAmbush Commander wrote:Could you post some code? There's probably something wrong with your cURL code... the syntax is a bit obtuse.
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;
?>- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
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.
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
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?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.