gpt4 book ai didi

php - 突然 pdf 不再上传 (php/mysql)

转载 作者:行者123 更新时间:2023-11-30 22:38:02 27 4
gpt4 key购买 nike

我刚刚注册是因为我突然遇到了一个问题,目前为止运行良好的代码我之前在这里找到了一些非常好的答案。希望你们能再次帮助我,这次甚至是投票;)

$sql='SELECT projektKurz, projektTitelGer, projektTitelEng, projektTitelFr
FROM projects
WHERE PNO=?';

$statement=$mysqli->prepare($sql);
// FEHLERBEHANDLUNG
// var_dump($statement);
// echo "<br />";
// var_dump($mysqli->error);
$statement->bind_param("i", $PNO);
$statement->execute();
$statement->bind_result($projektKurz,$projektTitelGer,$projektTitelEng,$projektTitelFr);
$statement->fetch();
$statement->store_result();
$statement->free_result();

$report="";
$allowedExts = array("xls", "xlsx", "doc", "docx", "ppt", "pptx", "pdf", "zip", "rar", "gif", "jpeg", "jpg", "png", "bmp");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "application/vnd.ms-excel")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|| ($_FILES["file"]["type"] == "application/msword")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|| ($_FILES["file"]["type"] == "application/vnd.ms-powerpoint")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.presentationml.presentation")
|| ($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "application/x-pdf")
|| ($_FILES["file"]["type"] == "application/acrobat")
|| ($_FILES["file"]["type"] == "application/vnd.pdf")
|| ($_FILES["file"]["type"] == "text/pdf")
|| ($_FILES["file"]["type"] == "text/x-pdf")
|| ($_FILES["file"]["type"] == "application/force-download")
|| ($_FILES["file"]["type"] == "application/x-octet-stream")
|| ($_FILES["file"]["type"] == "application/zip")
|| ($_FILES["file"]["type"] == "application/x-rar-compressed")
|| ($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/bmp"))
&& ($_FILES["file"]["size"] < 100000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
$report .= "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
$report .= "Upload: " . $_FILES["file"]["name"] . "<br />
Type: " . $_FILES["file"]["type"] . "<br />
Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br />
Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists("projekte/".$projektKurz."/" . $_FILES["file"]["name"]))
{
$report .= $_FILES["file"]["name"] . " existiert schon! ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"projekte/".$projektKurz."/" . $_FILES["file"]["name"]);
$report .= "Gespeichert unter: projekte/".$projektKurz."/" . $_FILES["file"]["name"];
}
}
}
else
{
$report .= "Ungueltige Datei!";
}
header("Location: projectupload.php?PNO=$PNO");

我已经使用这段代码大约 3 年了,没有任何问题。现在突然我上传有问题。 PDF 不再上传。图片有效,doc(旧版 MS Word)、docx、xlsx 也有效。

到目前为止,我已经设置了更高的权限 (777),为 pdf 添加了额外的 mime 类型(以前我只有 application/pdf)并尝试更改文件夹的所有者,但没有解决问题。

文件大小不是问题,我以前上传过 50 MB 的文件,现在连 44kb 的 pdf 文件都被拒绝了。

我也找不到可以在线解释此问题的 MIME 类型的任何最新更改。

我在使用 docx、xlsx 和 pptx 时遇到了同样的问题,但是一旦我插入了这些较新文档的 mime 类型,这个问题就得到了解决(即使它以前也适用于旧文档、xls 和 ppt 的 mime 类型) .

当我现在尝试上传 pdf 文件时,我被退回了:

Ungueltige Datei!

我没有想法,希望你们有更多的想法;)

更新 1:

按照建议,我已经激活了顶部的 var_dump,它让我得到了这个:

object(mysqli_stmt)#2 (10) { ["affected_rows"]=> int(0) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(1) ["field_count"]=> int(4) ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["sqlstate"]=> string(5) "00000" ["id"]=> int(1) }

string(0) ""

最佳答案

很可能在这种情况下,$_FILES["file"]["type"] 的 值出于某种原因是一个 字符串。

上传文件时,最好在一开始就检查错误 $_FILES["file"]["error"]。如果其值等于 0,则继续文件类型检查,否则返回相应的消息错误。

Here you can find the possible error values

关于php - 突然 pdf 不再上传 (php/mysql),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31875057/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com