dongping5230
2018-03-23 14:19PHP cURL文件获取内容始终为空
I've created an endpoint in Paw (and/or Postman) for handling file uploads. It works great!
It's pretty simple. And in my application I can do something like:
echo file_get_contents('php://input');
And it will print out an encoded representation of the image/file (a cute kitten).
The problem is, I cannot seem to reproduce this behaviour using just cURL (Current application uses Guzzle).
When I try something like:
$target_url = 'http://my-document-handling-service.net:8000/documents';
$request = curl_init($target_url);
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_POSTREDIR, 3);
curl_setopt(
$request,
CURLOPT_POSTFIELDS,
array(
'file' => '/Users/xxxxxxx-xxxx/Documents/kitten-test-upload-image-1.jpg'
));
echo curl_exec($request);
curl_close($request);
The body (file_get_contents()
) is always empty. I don't really understand cURL I've always just used Guzzle - but now I have to use cURL and I can't get the body.
What am I doing wrong?
- 点赞
- 回答
- 收藏
- 复制链接分享
2条回答
为你推荐
- 从服务器读取响应,作为文件下载
- curl
- json
- xampp
- php
- 1个回答
- 远程解析XML与使用cURL本地保存文件并在本地解析
- curl
- xml
- php
- parsing
- mysql
- 1个回答
- cURL HTTPS遵循重定向
- curl
- php
- 1个回答
- 将文件从本地文件系统复制并处理到另一台服务器的db
- curl
- php
- 2个回答
- 如何使用php中的curl将文件从本地上传到服务器?
- curl
- file-upload
- php
- 1个回答
换一换