PHP转换图像以添加多部分表单数据
我在使用API时遇到了一些困难。它要求我创建一个多部分表单数据映像PHP转换图像以添加多部分表单数据,php,image,forms,api,multipart,Php,Image,Forms,Api,Multipart,我在使用API时遇到了一些困难。它要求我创建一个多部分表单数据映像 POST https://api.working.com/v1/detail/detail.example.id1/27f145d2-5713-4a8d-af64-b269f95ade3b/images/thumbnail/normal ------------------------------330184f75e21 Content-Disposition: form-data; name="image"; filenam
POST https://api.working.com/v1/detail/detail.example.id1/27f145d2-5713-4a8d-af64-b269f95ade3b/images/thumbnail/normal
------------------------------330184f75e21
Content-Disposition: form-data; name="image"; filename="icon.png"
Content-Type: application/octet-stream
.PNG
imagedata
Response
我试图找到一些PHP脚本的例子,将图像转换成这种格式
图像文件必须在多部分表单数据中具有名称image
我绞尽脑汁,在互联网上寻找适合我的东西
有没有人可以分享一个片段来帮助你
谢谢
Rob下面是一个基本的卷曲示例,演示如何进行卷曲:
$url = 'https://api.working.com/v1/detail/detail.example.id1/27f145d2-5713-4a8d-af64-b269f95ade3b/images/thumbnail/normal';
$data = array(
'image' => new CURLFile(
'/path/to/icon.png',
'application/octet-string',
'icon.png'
),
'some_other_field' => 'abc',
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response = curl_exec($ch);
// do something with response
// to debug, try var_dump(curl_getinfo($ch)); and var_dump(curl_error($ch));
$ch = curl_init($url);
有关文件上载的详细信息和更多请求选项,请查看该类。您可以使用创建这样的多部分请求来将图像上载到服务器。@drew010这就是我一直希望做的。你能说得更具体些吗?我点击了你提供的链接,但它只会显示不同卷曲类型的列表。你太棒了。非常感谢你。我花了好几天的时间想弄明白这一点。你这个男人!!!!!!!!