我正在尝试实现一个简单的文件上传脚本。这是代码:
<?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\
、 toC:\inetpub\wwwroot\upload
和 to C:\inetpub\wwwroot\Italia\nada
。不仅如此,我已经尝试过使用ini_set()
. 最糟糕的是,我什至将 PHP 升级到 5.4,但它仍然无法正常工作(并且在每种情况下,我都会在完全相同的上传文件夹中遇到完全相同的错误,在 中Windows\Temp
)。
我在这里做错了什么?