我正在尝试实现一个简单的文件上传脚本。这是代码:
<?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;
}
?>
这是输出
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
在php.ini中我有这个:
upload_tmp_dir=C:\inetpub\wwwroot\upload
问题:我已将权限设置为C:\Windows\Temp\
,C:\inetpub\wwwroot\upload
和C:\inetpub\wwwroot\Italia\nada
。不仅如此,我已经尝试了ini_set()
。最糟糕的是,我甚至将PHP升级到5.4并且它仍然无法正常工作(并且在每种情况下,我都会在Windows\Temp
)中使用完全相同的上传文件夹获得完全相同的错误。
我在这里做错了什么?
答案 0 :(得分:0)
答案非常简单:我必须将完全权限设置为USERS
。