我在将 move_upload_file() 函数引用到另一个页面时遇到问题。它的工作没有任何错误。但问题是所选文件没有被传输到指定目录。
我不知道问题是什么,并且感谢任何类型的帮助或建议。
这是代码:
第 1 页(正在进行输入):
<form name='NewsForm' method='post' action='conf_news.php' enctype='multipart/form-data' >
<input type="file" name="file" id="file" value='' >
<input type='submit' name='AddNews' value='POST' >
</form>
它将代码带到另一个页面“conf_news.php”,我在其中引用了存储文件的部分内容: 第 2 页:
$PicMessage = "";
$PicName = addslashes( $_FILES["file"]["name"] );
$PicType = addslashes( $_FILES['file']['type'] );
$PicSize = addslashes( $_FILES['file']['size'] );
$PicError = addslashes( $_FILES["file"]["error"] );
$PicTempName = addslashes( $_FILES["file"]["tmp_name"] );
$allowedExt = array('jpeg', 'jpg', 'gif', 'png');
$a = explode(".", $PicName);
$extension = end($a); unset($a);
if((($PicType == "image/gif")
|| ($PicType == "image/png")
|| ($PicType == "image/jpeg")
|| ($PicType == "image/jpg")
&& ($PicSize > 100)
&& in_array($extentions, $allowedExt))){
if($PicError > 0){
$PicMessage = "Error Type: ". $PicError. "<br />";
}
else{
echo "Upload: ". $PicName. "<br />";
echo "Type: ". $PicType. "<br />";
echo "Size: ". ($PicSize / 1024). " Kb<br />";
echo "Stored in: ". $PicTempName;
if(file_exists("../photos/". $PicName)){
$PicMessage = "File Already Exists";
}
else{
move_uploaded_file($PicTempName, "../photos/". $PicName);
$PicMessage = "Stored in: ". "../photos/". $PicName;
}
}
}
else{
$PicMessage = "Invalid File Type";
}
图片消息显示文件已传输,但 ptohos 文件夹为空。我实在想不出哪里出了问题。
提前非常感谢所有愿意花时间帮助我的人。
最佳答案
好的,我发现问题了。
in_array($extentions, $allowedExt))){ 将其更改为 $extension。这是一个小错误,但足以延迟我们的工作。同时删除 add_slashes( )并尝试。
关于php - move_uploaded_file() 函数在引用另一个页面时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14035536/