或者PHP不允许这样做?我已经读过它可以使用PUT,但服务器仅期望POST。是否可以使用cURL来上传使用POST文件?
6
A
回答
1
是的,它有可能流上传一个文件使用POST文件上传与cURL。这是默认设置,您需要提供想要以字符串形式流式传输的文件的文件名。
// URL on which we have to post data
$url = "http://localhost/tutorials/post_action.php";
// Any other field you might want to catch
$post_data['name'] = "khan";
// File you want to upload/post
$post_data['file'] = "@c:/logs.log";
// Initialize cURL
$ch = curl_init();
// Set URL on which you want to post the Form and/or data
curl_setopt($ch, CURLOPT_URL, $url);
// Data+Files to be posted
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
// Pass TRUE or 1 if you want to wait for and catch the response against the request made
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// For Debug mode; shows up any error encountered during the operation
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Execute the request
$response = curl_exec($ch);
// Just for debug: to see response
echo $response;
除此之外默认方法,它是不可以使用卷曲到流上传使用POST方法的文件。
5
卷曲已经支持流,尝试curl --help | grep binary
你会得到:
“--data-二进制数据HTTP POST二进制数据(H)”
一个例子: curl -v -XPOST http://example:port/path --data-binary @file.tar \ -H "Content-Type: application/octet-stream"
相关问题
- 1. 是否可以使用POST直接从URL上传到S3?
- 2. 是否可以使用cURL通过SSH抓取文件?
- 3. 可能使用curl上传外部json文件而不是--data?
- 4. 是否可以使用RestSharp执行异步文件上传?
- 5. 是否可以使用Paperclip上传.mov文件?
- 6. 是否可以取消使用隐藏iframe的文件上传?
- 7. 是否可以使用Ajax做文件上传?
- 8. 是否可以使用PHP将文件从FTP上传到FTP
- 9. 是否可以使用XHR上传文件的目录?
- 10. 使用curl上传包含文件的POST数据
- 11. 如何使用CURL POST将文件流直接上传到Flickr?
- 12. 是否可以只使用POST请求?
- 13. 使用curl上传多个文件
- 14. 使用cURL上传文件内容
- 15. 使用PHP上传文件CURL
- 16. 使用CURL接受文件上传php
- 17. 是否可以使用HTTP POST下载文件?
- 18. 我想知道我可以使用JQuery $ .post来上传文件吗?
- 19. 我可以使用CURL来调用相同的文件吗?
- 20. 是否可以使用HTML按钮上传文件以用于W3C File API?
- 21. 是否可以使用批处理文件将文件上传到网站?
- 22. 是否可以使用Valence将文件上传到“管理文件”区域?
- 23. jshell是否可以使用jmod文件?
- 24. 使用cURL下载http post(ed)文件
- 25. Windows PHP cURL上传不在POST文件
- 26. 使用AFNetworking上传POST文件
- 27. 使用jquery post的PHP文件上传
- 28. 上传文件使用$ post jquery函数
- 29. 使用POST的JavaScript文件上传Nodejs
- 30. 使用POST将文件上传到s3
我相信[pecl_http](http://pecl.php.net/package/pecl_http)能够在2.x分支中做到这一点。 –
重复的http://stackoverflow.com/questions/3085990/post-a-file-string-using-curl-in-php – bwoebi
服务器需要接受这与内容类型application/octet-stream。 – rosc0