Jump to content

cURL and image upload field


rednax

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.