我正在研究一个简单的php脚本,允许我上传图片。正确的文件上传,但是当我去打开有一个errore目录上传图片“你无权看到此文件,检查权限,然后重试”Move_uploaded_file()权限
<!DOCTYPE html>
<html>
<head>
<title> File upload </title>
<meta charset = "UTF-8" />
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Seleziona il file:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
<?php
$target_dir = "C:\Users\test\Desktop\upload_succeeded\\";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$fileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Controllo se il file esiste gia
if (file_exists($target_file))
{
echo "Spiacenti, il file esiste gia'.";
$uploadOk = 0;
}
// Abilitare solo alcuni formati di file
if($fileType != "jpg" && $fileType != "png" && $fileType != "jpeg" && $fileType != "gif")
{
echo "Spiacenti, solo file JPG, JPEG, PNG & GIF sono abilitati.";
$uploadOk = 0;
}
// Controllo se $uploadOk e' settato a 0 da un errore
if ($uploadOk == 0)
{
echo "Spiacenti, il tuo file non e' stato caricato.";
// Se tutto e' ok prova a caricare il file
}
else
{
if(move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file))
{
echo "Il file ". basename($_FILES["fileToUpload"]["name"]). " e' stato correttamente caricato.";
}
else
{
echo "Spiacenti, c'e' stato un errore nel caricamento del file.";
}
}
?>
这里提供的信息稍少一点,但我认为你的web服务器的另一个用户比你的桌面文件夹要多一些......通常最好使用相对路径和像“__DIR__”这样的常量。 – Oliver