我有一个PHP网站,我正在尝试创建一个人们可以将图像上传到服务器的页面。
然而它无法正常工作,我从files变量中得到错误代码6。
我研究了这个,显然这意味着它缺少一个临时目录,但是我已经在php.ini中正确设置了临时文件夹,但它仍然无法正常工作。
以下是$ _FILES数组的内容:
Array ( [fileToUpload] => Array ( [name] => maxresdefault.jpg [type] => [tmp_name] => [error] => 6 [size] => 0 ) )
编辑:我在Windows 10上运行IIS作为我的服务器
编辑:这是我的代码:
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$sys_vars["uploads"]++;
$target_dir = "../";
$target_file = $target_dir . $sys_vars["uploads"];
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$path_parts = pathinfo($_FILES["fileToUpload"]["name"]);
echo $_FILES["fileToUpload"]["error"];
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
$uploadOk = 0;
//header("Location: upload.php?error=File is not an image.");
echo "File is not an image.";
die();
}
}
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
//header("Location: upload.php?error=Sorry, your file is too large.");
die();
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") {
echo "Sorry, only JPG, JPEG & PNG files are allowed.";
echo $imageFileType;
echo $_FILES["fileToUpload"]["tmp_name"];
$uploadOk = 0;
//header("Location: upload.php?error=Sorry, only JPG, JPEG & PNG files are allowed.");
die();
}
if ($uploadOk == 0) {
echo "Your file was not uploaded.";
//header("Location: upload.php");
die();
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "/")) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
print_r ($_FILES);
//header("Location: upload.php?error=Sorry, there was an error uploading your file.");
die();
}
}
?>