[英]“Permission denied” when uploading files
I'm trying to implement a simple script for file uploading. 我正在尝试实现一个用于文件上传的简单脚本。 Here's the code:
这是代码:
<?php
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = strtolower(end(explode(".", $_FILES["fotocarnet"]["name"])));
if ((($_FILES["fotocarnet"]["type"] == "image/gif")
|| ($_FILES["fotocarnet"]["type"] == "image/jpeg")
|| ($_FILES["fotocarnet"]["type"] == "image/png")
|| ($_FILES["fotocarnet"]["type"] == "image/pjpeg"))
&& ($_FILES["fotocarnet"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["fotocarnet"]["error"] > 0)
{
echo "Return Code: " . $_FILES["fotocarnet"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["fotocarnet"]["name"] . "<br>";
echo "Type: " . $_FILES["fotocarnet"]["type"] . "<br>";
echo "Size: " . ($_FILES["fotocarnet"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["fotocarnet"]["tmp_name"] . "<br>";
if (file_exists("nada/" . $_FILES["fotocarnet"]["name"]))
{
echo $_FILES["fotocarnet"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["fotocarnet"]["tmp_name"],
'nada/' . $_FILES["fotocarnet"]["name"]);
echo "Stored in: " . "nada/" . $_FILES["fotocarnet"]["name"];
}
}
}
else
{
echo "Invalid file: ".$extension;
}
?>
Here's the output 这是输出
Upload: MARTÍNEZGARCÍAGIANCKO.JPG
Type: image/jpeg
Size: 3.6513671875 kB
Temp file: C:\Windows\Temp\phpE21C.tmp
Warning: : failed to open stream: Permission denied in C:\inetpub\wwwroot\Italia\IngSubirFotoCarnetIns_Italia.php on line 29
Warning: move_uploaded_file(): in C:\inetpub\wwwroot\Italia\IngSubirFotoCarnetIns_Italia.php on line 29
Stored in: nada/MARTÍNEZGARCÍAGIANCKO.JPG
And in php.ini I have this: 在php.ini中,我有这个:
upload_tmp_dir=C:\inetpub\wwwroot\upload
The catch: I've already set the permissions to C:\\Windows\\Temp\\
, to C:\\inetpub\\wwwroot\\upload
and to C:\\inetpub\\wwwroot\\Italia\\nada
. 要注意的是:我已经将权限设置为
C:\\Windows\\Temp\\
, C:\\inetpub\\wwwroot\\upload
和C:\\inetpub\\wwwroot\\Italia\\nada
。 Not only that but I already tried with ini_set()
. 不仅如此,我已经尝试过
ini_set()
。 Worst, I even upgraded PHP to 5.4 and it's still not working (and in every case I get the exact same error with the exact same upload folder, in Windows\\Temp
). 更糟糕的是,我什至将PHP升级到5.4,但仍然无法正常工作(在每种情况下,在
Windows\\Temp
,使用完全相同的上载文件夹都会出现完全相同的错误)。
What am I doing wrong here? 我在这里做错了什么?
答案很简单:我必须设置对USERS
完全权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.