rednax Posted June 20, 2008 Share Posted June 20, 2008 I'm trying to write a script that will fill out a remote form that contains a few text fields and an image upload field. The text fields work fine, but I cannot for the life of me get the image upload to work... Here is some sample code: (I've already connected with cURL and logged in to the form.) // Copy thumbnail over and rename $thumbLocation = "http://www.domain.com/thumbs/preview.jpg"; $name = "test"; $newLocation = "thumbs/".$name.".jpg"; if (!copy($thumbLocation, $newLocation)) { echo "failed to copy.\n"; } $Location = "/usr/home/username/domains/domain.com/public_html/thumbs/".$name.".jpg"; $Fields = array('gallery_url' => $galleryURL, 'gallery_title' => $galleryTitle, 'newthumb' => $Location, 'save' => 'Insert'); $o = ""; foreach ($Fields as $key => $value) { $o .= urlencode($key). "=" .urlencode($value)."&"; } $Fields = substr($o,0,-1); // lose last & // Now I have a query string [$Fields] to submit to the form curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $Fields); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0); $submitIt = curl_exec($ch); I guess my question is... am I okay to supply the local file path as the value for the image upload field - or am I misunderstanding something? I've tried giving it just the relative path, absolute etc without luck? Link to comment https://forums.phpfreaks.com/topic/111040-curl-and-image-upload-field/ Share on other sites More sharing options...
DarkWater Posted June 20, 2008 Share Posted June 20, 2008 You may need to post the binary data of the image to the script....no....maybe not...I'm not sure if there's an easy way to upload an image with cURL. Link to comment https://forums.phpfreaks.com/topic/111040-curl-and-image-upload-field/#findComment-569810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.