简体   繁体   English

HTTP PUT请求:通过文件传递参数

[英]HTTP PUT Request: Passing Parameters with File

After numerous various tests with uploading files throught HTTP POST Request, it looks that HTTP PUT Requests are the most suitable for very large files +1GB upload. 在通过HTTP POST Request上传文件的各种测试之后,看起来HTTP PUT Request最适合+ 1GB的超大文件上传。

The below listed simple code I have tested for HTTP PUT file upload request works well: 我为HTTP PUT文件上传请求测试的以下列出的简单代码效果很好:

JavaScript: JavaScript的:

var req = createRequest();
req.open("PUT", "PHP/filePutLoad.php");
req.setRequestHeader("Content-type", "text/plain");
req.onload = function (event)
{
    console.log(event.target.responseText);
}
req.send(aUploadedFile.file_object);

PHP: PHP:

include 'ChromePhp.php';
require_once 'mysqlConnect.php';

ini_set('max_execution_time', 0);

ChromePHP::log( '$_PUT :' . print_r($_PUT));

/* PUT data comes in on the stdin stream */
$putdata = fopen("php://input", "r");

/* Open a file for writing */
$fp = fopen("myputfile.ext", "w");

/* Read the data 1 KB at a time and write to the file */
while ($data = fread($putdata, 1024))
    fwrite($fp, $data);

/* Close the streams */
fclose($fp);
fclose($putdata);

However, I have difficulties delivering arguments and variables with the file being uploaded from JavaScript to PHP. 但是,在将参数和变量从JavaScript上载到PHP时,我很难传递参数和变量。 For example, I need to deliver upload target folder, where the new data needs to be stored, ID of the uploader, etc.. 例如,我需要交付上载目标文件夹,需要存储新数据的位置,上载者的ID等。

  • Is there a way to combine HTTP PUT Request with HTTP POST to submit arguments? 有没有一种方法可以结合使用HTTP PUT Request和HTTP POST来提交参数?
  • What are my options if I wish to deliver parameters from JavaScript to PHP along HTTP PUT file upload? 如果我希望通过HTTP PUT文件上传将参数从JavaScript传递到PHP,该怎么办?

Thank you. 谢谢。

using PUT also, it works when you append the parameters in the query string. 也使用PUT,当您将参数附加到查询字符串中时,它就可以工作。 I'm also looking for another way for this. 我也在寻找另一种方法。 Although, this is a workaround I'm using currently 虽然,这是我目前正在使用的解决方法

curl -X PUT " http://www.my-service.com/myservice?param1=val1 " --data @file.txt curl -X PUT“ http://www.my-service.com/myservice?param1=val1 ” --data @ file.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM