douxia9826 2012-11-13 04:49
浏览 42
已采纳

上传表单仅在上传ASCII .stl 3D文件时在Firefox中有效

uploadform.html and upload_file.php (below) works fine in Firefox but fails in Chrome, IE, and Safari when uploading ASCII .stl 3D files. Error message is "Invalid file" and problem occurs with multiple computers and multiple .stl files. When I modify the code to support other file types like JPG and PDF it allows those file types in all four web browsers. Also, Firefox only allows the .stl upload if I include application/octet-stream in the mime types section. Why doesn't this work outside of Firefox?

uploadform.html:

<!doctype html>
<html>
<body>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

upload_file.php:

<!doctype html>
<html>
<body>
<?php
$allowedExts = array("stl");
$extension = end(explode(".", $_FILES["file"]["name"]));
if (
        (
   ($_FILES["file"]["type"] == "application/sla")
|| ($_FILES["file"]["type"] == "application/octet-stream")
|| ($_FILES["file"]["type"] == "text/plain")
|| ($_FILES["file"]["type"] == "application/unknown")
        )
&& ($_FILES["file"]["size"] < 2000000)
&& in_array($extension, $allowedExts)
    )
{
  if ($_FILES["file"]["error"] > 0)
            {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
            }
  else
            {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] /1024) . " KB<br />";

        if (file_exists("upload/" . $_FILES["file"]["name"]))
            {
  echo $_FILES["file"]["name"] . " already exists. ";
            }
else
      {
  move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . $_FILES["file"]["name"]);
  echo "successful upload";
      }
           }
}
else
        {
    echo "Invalid file";
        }
?>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • douxing5199 2012-11-26 06:54
    关注

    Solution: add application/netfabb to the section of allowed mime types. This is the mime type most browsers assign to .stl files. Firefox is an exception and identifies .stl files as application/octet-stream.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计