相关疑难解决方法(0)

如何在PHP中获取字符串的十六进制转储?

我正在调查PHP5中的编码.有没有办法获得字符串的原始十六进制转储?即字符串中每个字节(非字符)的十六进制表示?

php string encoding hex character-encoding

64
推荐指数
3
解决办法
7万
查看次数

为什么我不能从POST请求中提取zip文件?

我有一段客户端代码,可以从Google云端硬盘导出.docx文件并将数据发送到我的服务器.它非常简单,它只是导出文件,使其成为blob,并将blob发送到POST端点.

gapi.client.drive.files.export({
    fileId: file_id,
    mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}).then(function (response) {

    // the zip file data is now in response.body
    var blob = new Blob([response.body], {type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"});

    // send the blob to the server to extract
    var request = new XMLHttpRequest();
    request.open('POST', 'return-xml.php', true);
    request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    request.onload = function() {
        // the extracted data is in the request.responseText
        // do something with it
    };

    request.send(blob);
});
Run Code Online (Sandbox Code Playgroud)

这是我的服务器端代码,用于将此文件保存到我的服务器上,以便我可以使用它来执行操作:

<?php
file_put_contents('tmp/document.docx', fopen('php://input', 'r'));
Run Code Online (Sandbox Code Playgroud)

当我运行它时,该文件在我的服务器上创建.但是,我认为它已损坏,因为当我尝试解压缩它时(就像你可以用.docx做的那样),会发生这种情况:

$ mv tmp/document.docx tmp/document.zip
$ unzip tmp/document.zip
Archive:  document.zip
error …
Run Code Online (Sandbox Code Playgroud)

javascript php zip docx google-drive-api

8
推荐指数
2
解决办法
992
查看次数