2013-05-10 45 views
3

雖然試圖使用形式和PHP/IIS 7上傳文件的臨時文件,我得到這個消息:無法創建,同時上傳

PHP Warning: File upload error - unable to create a temporary file in Unknown on line 0 

我的形式:

<form action="acciones.php" id="form3" method="POST" enctype="multipart/form-data"> 
    <input type="hidden" value="3" name="accion"> 
    <input type="text" name="nombre" placeholder="Nombre"> 
     <input type="file" name="imagen" accept="image/x-png, image/gif, image/jpeg" /> 
    <input type="button" id="envio" class="button azul" value="Agregar" onclick="envios()"> 
</form> 

My PHP code and reference:

$target = "/images/"; 
$target = $target . basename($_FILES['imagen']['name']); 
//This gets all the other information from the form 
$name=$_POST['nombre']; 
$pic=($_FILES['imagen']['name']); 

//Writes the information to the database 
$query = "INSERT INTO Playeras (Nombre, Ruta) VALUES ('$name', $pic')"; 
mysql_query($query, $conexion -> conn) or die("Error: ".mysql_error()) ; 

//Writes the photo to the server 
if(move_uploaded_file($_FILES['imagen']['tmp_name'], $target)) 
{ 
    //Tells you if its all ok 
    echo "The file ". basename($_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
} 
else 
{ 
//Gives and error if its not 
echo "Sorry, there was a problem uploading your file."; 
} 

我設置的路徑爲臨時文件:

upload_tmp_dir = "C:/Users/server/Pictures/tmp" 

併爲IIS_IUSRS和IUSRS提供了總控制權限。但每一次,我都會得到這個錯誤。我不知道我做錯了什麼。如果有人能幫助我,那會很好。

+0

您是否已經創建了tmp目錄?嘗試創建tmp目錄來解決問題。 – soachishti 2013-05-10 19:06:24

+0

肯定的,它的存在,並具有權限 – aerojun 2013-05-10 19:09:41

+0

嘗試從PHP代碼的ini_set設置臨時路徑( 「upload_tmp_dir」, 「C:/用戶/服務器/圖片/ TMP」);或ini_set(「upload_tmp_dir」,「server/Pictures/tmp」); – soachishti 2013-05-10 19:36:38

回答

4

使它工作。

改變

upload_tmp_dir = "C:/Users/server/Pictures/tmp" to "C:\TEMP". 

C語言創建的文件夾TEMP,給的權限。似乎它只在連接到C:時才起作用。

0

我finaly發現了,爲什麼這個錯誤實際發生:

IUSR帳戶(或根據您的身份驗證設置PHP進程會模擬帳戶)需要能夠列舉的的父文件夾 upload_tmp_dir文件夾。

此行爲很奇怪,因爲日誌或會話文件夾不需要此權限。

我的解決方案是以下的(使用來自上述交的路徑):

  1. 創建的文件夾的 「C:/用戶/服務器/圖片/ TMP」
  2. 格蘭特修改權利IUSR(或其它用戶),該文件夾
  3. 創建的文件夾中的 「C:/用戶/服務器/圖片/ TMP /上傳」
  4. 編輯的php.ini:upload_tmp_dir = 「C:/用戶/服務器/圖片/ TMP /上傳」

或者您可以授予只讀在父文件夾「這只是文件夾中的」權利「C:/用戶/服務器/圖片/ tmp目錄」。在這種情況下,你不需要另一個子文件夾。