2013-02-06 57 views
1

我試圖實現一個簡單的文件上傳腳本。下面的代碼:上傳文件時出現「權限被拒絕」

<?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\uploadC:\inetpub\wwwroot\Italia\nada。不僅如此,而且我已經嘗試過ini_set()。最糟糕的是,我甚至將PHP升級到5.4,但它仍然無法正常工作(並且在每種情況下,我都會得到與上一個文件夾完全相同的錯誤,Windows\Temp)。

我在這裏做錯了什麼?

+0

你設置了什麼權限? – Evert

+1

完全控制'IIS_IUSRS' –

+0

Mike:我試着在運行時將'upload_tmp_dir'修改爲'C:\ inetpub \ wwwroot \ upload',它仍然將文件保存在Windows \ Temp中。 –

回答

0

答案很簡單:我必須將完全權限設置爲USERS