duanan1228 2014-05-29 19:01
浏览 38

上传文件所以我应该怎么做标题?

We successfully set up image uploading on our server with nginx. Everything gets posted to /upload and then redirects to /file for processing. The file gets uploaded and stored, but there are headers at the top of the file.

------WebKitFormBoundaryqUwBABts5uiLHgDN

Content-Disposition: form-data; name="picture"; filename="coldplay.jpg"

Content-Type: image/jpeg

What am I to do with this? Do I strip these headers out with PHP and then save the file again?

Is uploading files with these headers expected behavior?

Here is the form:

<form action="/upload/"  id="upload3" method="post">
    <input type="file" id="file" name="picture" value=""/>
    <input type="submit" onclick="return uploadFiles(this.form);">
</form>

and js:

<script type="text/javascript">

    function uploadFiles(form) {
          var formData = new FormData(form);

          var url = "/upload/";
          var xhr = new XMLHttpRequest();
          xhr.open('POST', url, true);
          xhr.onload = function(e) {
            if (this.status == 200) {
              console.log(this.responseText);
            }
          };

          xhr.send(formData);  // multipart/form-data

          return false;
    }
</script>
  • 写回答

1条回答 默认 最新

  • dongyu6276 2014-05-29 23:46
    关注

    I'm using these lines of code to strip the first four lines from our uploaded image files. I found it somewhere on SO and it works great -- unfortunately I don't know where it was.

    $line_to_strip = 4;
    $new_file = new SplFileObject($file_full_new, 'w');
    foreach (new LimitIterator(new SplFileObject($file_full), $line_to_strip) as $line)
        $new_file->fwrite($line); 
    

    I don't know if this is our permanent solution, however.

    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来