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?