这就是我在process.php中所拥有的
parse_str(file_get_contents("php://input"),$upload_data); if (isset($upload_data)) { print_r($upload_data); exit; }这是我使用curl查询服务器的方式。
weldan@prindu:~$ curl -X PUT -H "X-TOKEN: test123" -F filedata=@/home/weldan/Pictures/Cool-Pictures1.jpg http://host.tld/process.php Array ( [------------------------------22031b6e799c Content-Disposition:_form-data;_name] => "filedata"; filename="Cool-Pictures1.jpg" Content-Type: image/jpeg ��� )所以我怎么知道那里有上传的文件。
目前的问题是,如何像$ _FILES变量一样处理这个文件?
打开其他方式来实现这一目标。
谢谢
this is what i have in process.php
parse_str(file_get_contents("php://input"),$upload_data); if (isset($upload_data)) { print_r($upload_data); exit; }this is how i query to server using curl.
weldan@prindu:~$ curl -X PUT -H "X-TOKEN: test123" -F filedata=@/home/weldan/Pictures/Cool-Pictures1.jpg http://host.tld/process.php Array ( [------------------------------22031b6e799c Content-Disposition:_form-data;_name] => "filedata"; filename="Cool-Pictures1.jpg" Content-Type: image/jpeg ��� )so that how i know there is uploaded file there.
current problem is, how do I process this file like $_FILES variable?
open for other way to achieve this too.
Thanks
最满意答案
在PUT请求中填充$ _FILES数组。 那是因为PUT请求将指定url中的文件名和正文中的文件内容。 而已。
你必须按照你的建议使用php://input 。
upload.php的
<?php /* PUT data goes to php://input */ echo file_get_contents("php://input");然后使用以下curl命令行:
curl --upload -H "X-TOKEN: test123" a.txt http://localhost/upload.php注释后更新 :使用--upload选项应该符合您的需求。 与-X PUT和-F不同,数据将被原始发送并且不会被多部分/表格数据编码。卷曲的隐藏宝藏之一;)
The $_FILES array being populated on PUT requests. That's because a PUT request will specify the file name in the url and the file content in the body. Nothing more.
You'll have to use php://input as you already suggested.
upload.php
<?php /* PUT data goes to php://input */ echo file_get_contents("php://input");Then use the following curl command line:
curl --upload -H "X-TOKEN: test123" a.txt http://localhost/upload.phpUpdate after comments: Using the --upload option should fit your needs. In difference to -X PUT together with -F, the data will be send raw and get not multipart/form-data encoded.. One of the hidden treasures of curl ;)
更多推荐
发布评论