dqg63264 2016-03-29 13:42
浏览 91

FormData附加到$ _POST而不是$ _FILES?

I'm trying to implement an upload routine for huge files, for this I'm chunking the file and send chunk by chunk to server so far so good.

Now to identify the chunk-parts, I'm trying to send some more information than the pure filepart in FormData.

var xhr = new XMLHttpRequest();
xhr.open("POST", 'upload.php', true);

var formData = new FormData();
formData.append("chunkpart", blob); // blob is Blob() or BlobBuilder
formData.append("chunkNumber", sendCount); // sendCount is an integer
formData.append("maxChunks", Math.ceil(maxChunks)); // maxChunks is a floatingpoint
formData.append("fileID", fileID); // fileID is an almost unique string
xhr.send(formData);

On the php side the chunkpart is found in $_FILES however chunkNumber, maxChunks and fileID are found in $_POST.

My question here: Am I doing something wrong or did I just misunderstood how FormData works and how can I get it work like I expected?

  • 写回答

1条回答 默认 最新

  • doutun1362 2016-03-29 14:03
    关注

    This is simply how posted content works with BLOB data. It gets uploaded as a "file" in a multipart form post. In PHP this type of form data is in the $_FILES variable and not the $_POST.

    Is there some reason that you can't grab data from both $_POST and $_FILES? I do that regularly when processing posting form content that includes files/images.

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮