gpt4 book ai didi

php - 为什么以下代码在 PHP 中上传文件时会抛出 undefined index ?

转载 作者:行者123 更新时间:2023-11-29 06:57:48 25 4
gpt4 key购买 nike

将问题标记为重复是徒劳的,因为我已经在 SO 上提到了所有此类问题,但没有一个提供解决方案。

<?php 
if(isset($_POST['submit'])){
$name=$_FILES['filedoc']['name'];
$temp_name=$_FILES['filedoc']['tmp_name'];
if(isset($name)){
if(!empty($name)){
$file=file_get_contents($temp_name);
}
}
else echo"Please upload file";

echo "<form action=\"";echo htmlentities($_SERVER["PHP_SELF"]);echo "\" method=\"post\">
<h2>New Paste</h2>
<label> Upload File? <input type = \"file\" name = \"filedoc\"/></label><br><span class=\"error\">";echo $fileErr;echo"</span><br>
<input id=\"button\"class=\"red\" type =\"submit\" class=\"red\" name=\"submit\" value = \"Paste\"/><br><span class=\"error\">";echo $submitErr;echo "</span>
</form>";
}
?>

表单显示正确。所以第二部分没有错误。但是然后,我收到此错误(!)注意:未定义索引:文件路径中的 filedoc 文件

最佳答案

缺少表单属性enctype="multipart/form-data"

关于php - 为什么以下代码在 PHP 中上传文件时会抛出 undefined index ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44899934/

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