Php 使用curl从文件\u get\u contents/imagecreatefromstring上载
我有以下代码:Php 使用curl从文件\u get\u contents/imagecreatefromstring上载,php,stream,Php,Stream,我有以下代码: $image = imagecreatefromstring(file_get_contents('http://externaldomain.com/image.png')); 并要发出卷曲请求: $files = array(); $files[] = '@' . $image['tmp_name'] . ';filename=' . $image['name'] . ';type=' . $image['type']; $ch = curl_init('index.ph
$image = imagecreatefromstring(file_get_contents('http://externaldomain.com/image.png'));
并要发出卷曲请求:
$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);
主要问题是,如何从$image
变量获取文件名和扩展名
我可以用tempnam()
替换$image['tmp\u name']
,但是其他东西呢
还有其他方法吗?imagecreatefromstring返回一个GD句柄。没有与之关联的tmp_名称、名称、或类型。您试图将该GD句柄视为标准的基于POST的$\u文件数据结构的结果 GD句柄不能传递给curl进行上传,因为它不是真正的图像,并且在使用imagejpeg/imagepng/ImageAnywhere将其保存到文件中之前不会传递给curl,然后可以将curl指向该文件,例如
$image = imagecreatefromstring(...);
imagejpeg($image, 'tempfile.jpg');
$files[] = '@tempfile.jpg;filename=tempfile.jpg;type=image/jpeg';
curl...
imagecreatefromstring返回一个GD句柄。没有与之关联的tmp_名称、名称、或类型。您试图将该GD句柄视为标准的基于POST的$\u文件数据结构的结果 GD句柄不能传递给curl进行上传,因为它不是真正的图像,并且在使用imagejpeg/imagepng/ImageAnywhere将其保存到文件中之前不会传递给curl,然后可以将curl指向该文件,例如
$image = imagecreatefromstring(...);
imagejpeg($image, 'tempfile.jpg');
$files[] = '@tempfile.jpg;filename=tempfile.jpg;type=image/jpeg';
curl...