Retrieve Uploaded Blob with PHP(使用 PHP 检索上传的 Blob)
问题描述
我有一个创建 blob 并将其发布到 PHP 文件的脚本.这是我的代码:
I have a script that is creating a blob and posting it to a PHP file. Here is my code:
HTML/Javascript:
<script type="text/javascript">
function upload() {
var data = new FormData();
data.append('user', 'person');
var oReq = new XMLHttpRequest();
oReq.open("POST", 'upload.php', true);
oReq.onload = function (oEvent) {
// Uploaded.
};
var blob = new Blob(['abc123'], {type: 'text/plain'});
oReq.send(blob);
}
</script>
<button type="button" onclick="upload()">Click Me!</button>
PHP:
<?php
var_dump($_POST);
?>
当我查看我的开发人员控制台时,我的 PHP 页面上没有收到任何 $_POST 数据.我需要知道如何检索发布到 PHP 脚本的文本文件.
When I look at my developer console, I am not getting any $_POST data on my PHP page. I need to know how to retrieve the text file being posted to PHP script.
非常感谢任何帮助!
推荐答案
可以从 php://input
中读取 blob 中的数据,如
The data from the blob can be read from php://input
, as in
<?php
var_dump(file_get_contents('php://input'));
但是,如果您想使用表单数据对象发送多条数据,它就像一个普通的多部分/表单数据帖子.所有字符串都可以通过 $_POST
获得,所有 blob 和文件都可以通过 $_FILES
获得.
If however you want to send multiple pieces of data with a form data object it would be like a normal multipart/form-data post. All string would be available through $_POST
and all blobs and file through $_FILES
.
function upload() {
var data = new FormData();
var oReq = new XMLHttpRequest();
oReq.open("POST", 'upload.php', true);
oReq.onload = function (oEvent) {
// Uploaded.
};
var blob = new Blob(['abc123'], {type: 'text/plain'});
data.append('file', blob);
oReq.send(data);
}
这篇关于使用 PHP 检索上传的 Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 PHP 检索上传的 Blob


基础教程推荐
- 超薄框架REST服务两次获得输出 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01