cURL Help (Again)

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 (Again)

Post by TS_Death_Angel »

I've made some progress... after being unable to upload images using the normal POST method, I thought it'd be easier to just use the 'upload from URL' option. For those of you who don't remember what I was making, it's a script to upload images to ImageShack. Here's what I've got so far:

Code: Select all

<?

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

$post = '-----------------------------158701408529245\r\n
Content-Disposition: form-data; name="uploadtype"\r\n
\r\n
on\r\n
-----------------------------158701408529245\r\n
Content-Disposition: form-data; name="fileupload"; filename=""\r\n
Content-Type: application/octet-stream\r\n
\r\n
\r\n
-----------------------------158701408529245\r\n
Content-Disposition: form-data; name="url"\r\n
\r\n
http://prefbar.mozdev.org/getsuite.png\r\n
-----------------------------158701408529245\r\n
Content-Disposition: form-data; name="MAX_FILE_SIZE"\r\n
\r\n
3145728\r\n
-----------------------------158701408529245\r\n
Content-Disposition: form-data; name="refer"\r\n
\r\n
\r\n
-----------------------------158701408529245\r\n
Content-Disposition: form-data; name="brand"\r\n
\r\n
\r\n
-----------------------------158701408529245\r\n
Content-Disposition: form-data; name="optimage"\r\n
\r\n
1\r\n
-----------------------------158701408529245\r\n
Content-Disposition: form-data; name="optsize"\r\n
\r\n
320x320\r\n
-----------------------------158701408529245--\r\n
';
	  
$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_POSTFIELDS, $post );

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

?>
I think it works, but all it returns in the front page of one of the ImageShack servers. Any help? :)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

\r, \n and every other backslashed sequence does not work in single quotes. Try double quotes and see if it work for your.
TS_Death_Angel
Forum Commoner
Posts: 31
Joined: Sat Dec 31, 2005 8:49 am

Post by TS_Death_Angel »

No luck... :(
Post Reply