(CURL, PHP) Uploading files with PUT request, How do I process this?

后端 未结 2 851
执笔经年
执笔经年 2021-01-21 23:51

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;
}
         


        
2条回答
  •  长发绾君心
    2021-01-22 00:03

    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

    Then use the following curl command line:

    curl --upload -H "X-TOKEN: test123" a.txt  http://localhost/upload.php
    

    Update 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 ;)

提交回复
热议问题