CURL to HTTP_PUT or POST an image from a container field
I want to http_PUT (or POST) an image ( a gif) to a URL. I want to store this image in a container field first inside filemaker and then post it.
I have been trying this SmartPill PHP code...
Lets say that the container field is called piccontainer...
$expression = 'Get(piccontainer)';
$datain = fm_evaluate($expression);
$ctype= "image/gif";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://garytest.nordic-e.com/__API__/picture/8/data");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD,"testuser:testpass");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type" => $ctype));
curl_setopt($ch, CURLOPT_POSTFIELDS, $datain);
$data = curl_exec($ch);
print curl_error($ch);
echo $data;
curl_close($ch);
I don't get any error messages, but I dont get any picture either!
I have also tried the first line of the script as "$expression = 'getContainerData(piccontainer)';" but with the same results.
Can anyone see where I am going wrong?
All the best,
Gary
A bit of progress
Hi,
I have made a bit of progress with this. The following code works well to grap an image from a URL and then upload it to my webservice. My problem however is how to get the image from a container field instead of a URL.
I am using Windows. Can anyone help?
$url = 'http://sprott.physics.wisc.edu/fractals/carlson/PGPHX82.GIF';
$datain = file_get_contents($url);
$ctype= "image/gif";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://garytest.nordic-e.com/__API__/picture/8/data");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD,"testuser:testpass");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type" => $ctype));
curl_setopt($ch, CURLOPT_POSTFIELDS, $datain);
$data = curl_exec($ch);
print curl_error($ch);
echo $data;
curl_close($ch);
A bit of progress
Hello Gary,
See my reply on your other curl posting. The short of it is you need to export the file in the container field to disk first. SmartPill can't read container fields directly.
Regards,
Micah