2017-02-02 180 views
-1

我在localhost上有一些代碼,它們工作正常,但是當我把它們(html,php)放在活動服務器上時,它在第一個上傳部分 PHP端:上傳文件在localhost上工作正常,但在非服務器上工作

$target_dir = "wwwroot/aaa/html/temp/"; 
$target_file = $target_dir . $_FILES["fileToUpload"]["name"]; 
$uploadOk = 1; 
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 
if (file_exists($target_file)) { 
    $exist = "file has already been uploaded."; 
    $uploadOk = 0; 
} 
if ($uploadOk == 0) { 

} else { 
    if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_file)) { 
     $test="uploaded"; 
    } else { 
     $fail="fail uploaded"; 
    } 
    } 
$tempfilename=$_FILES['fileToUpload']['tmp_name']; 
$array=array("$tempfilename","$fail"); 
echo json_encode($array); 

在HTML端:

<input type="file" id="fileToUpload" name="fileToUpload"></input> 




$.ajax({ 
      url: 'loadfile.php', 
      type: 'POST', 
      data: formData, 
      async: false, 
      dataType: 'json', 
      success: function (html) { 
       loadfileName=html[0]; 
       alert(html[0]+' '+html[1]); 
      }, 
      cache: false, 
      contentType: false, 
      processData: false 
     }); 

警報總是 「/溫度/ someRandomCharacters」 + 「上傳失敗」,但在本地主機上工作正常。任何幫助讚賞。

+1

通常這是權限問題與目標目錄 – nogad

+0

那麼,你看着服務器上的錯誤日誌,看看是什麼問題?因爲這是你應該始終做的第一件事。 –

+0

@JonathanKuhn是的,「服務器的響應狀態爲403(禁止)」 – MMzztx

回答

1

要上傳到需要的文件夾已經權限設置爲775

+0

謝謝,從來沒有想過權限問題 – MMzztx

相關問題