I have the follow code:
$image = imagecreatefromstring(file_get_contents('http://externaldomain.com/image.png'));
And want to make a curl request:
$files = array();
$files[] = '@' . $image['tmp_name'] . ';filename=' . $image['name'] . ';type=' . $image['type'];
$ch = curl_init('index.php?route=upload');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $files);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
The main problem is, how to get the file name and extension from $image variable?
I can replace $image['tmp_name'] with tempnam(), but other things?
Have another way to do?
imagecreatefromstring returns a GD handle. There is no tmp_name, name, OR type associated with it. You’re trying to treat that GD handle as if it was the result of a standard POST-based $_FILES data structure.
a GD handle cannot be passed to curl for upload, because it’s not really an image, and won’t be until you use imagejpeg/imagepng/imagewhatever to save it out to a file, which you can then point curl at, e.g.