![](/img/trans.png)
[英]PHP - Uploading one or two files (large photos) works fine - uploading 5/6+ doesn't seem to even register (it just shows the upload form)
[英]upload form only works in Firefox when uploading ASCII .stl 3D files
uploadform.html和upload_file.php (下面)在Firefox中正常工作,但在上传ASCII .stl 3D文件时在Chrome,IE和Safari中失败。 错误消息是“无效文件”,多个计算机和多个.stl文件出现问题。 当我修改代码以支持其他文件类型(如JPG和PDF)时,它允许在所有四种Web浏览器中使用这些文件类型。 此外,如果我在mime类型部分中包含application / octet-stream,则Firefox仅允许.stl上载。 为什么这不能在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>
解决方案:将application/netfabb
添加到允许的mime类型部分。 这是大多数浏览器为.stl文件分配的mime类型。 Firefox是一个例外,它将.stl文件标识为application/octet-stream
。
尝试为IE设置编码属性。
<form action="upload_file.php" method="post" enctype="multipart/form-data" encoding="multipart/form-data" >
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.