我一直在寻找堆栈溢出和其他教程如何使用PHP上传文件。下面的脚本一直运行到if语句的条件是move_uploaded_file($ file_temp,$ file_destination),在这个点它回应“file not uploaded”。图片上传失败使用PHP - move_uploaded_file
包含chmod函数的if语句是我试图在上传文件夹中将文件权限更改为0777(我非常肯定地给出了读取和写入访问权限),因为这已经是许多相关堆栈的建议溢出答案。虽然在这一点上我不认为问题是文件许可。
所以基本上我不知道这有什么问题。帮助表示赞赏:)
<form action="upload.php" method="post" enctype="multipart/form-data">
Your Photo: <input type="file" name="image" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
print_r($_FILES);
// file properties
$file_name = $_FILES['image']['name'];
$file_tmp_name = $_FILES['image']['tmp_name'];
$file_size = $_FILES['image']['size'];
$file_error = $_FILES['image']['error'];
// get the extension of the file
$file_ext = explode('.', $file_name);
$file_ext = strtolower(end($file_ext));
var_dump(file_exists('uploads'));
// this is false
if(chmod('uploads', 0777)){
echo " booooh";
}
else{
echo "naaah";
}
$file_name_new = uniqid('', true) . '.' . $file_ext;
echo "<br>";
echo $file_destination = '/uploads/' . $file_name;
// this is false too
if(move_uploaded_file($file_temp, $file_destination)) {
echo "<br>$file_destination<br>";
echo "hello world<br>";
}
else {
echo "<br>file not uploaded<br>";
}
?>
'var_dump(file_exists('uploads'));'是错误我想你检查存在的文件〜/上传或目录。检查'php.ini'中的选项'open_basedir' http://php.net/manual/en/ini.core.php#ini.open-basedir – Naumov