2014-11-24 96 views
0

我想上傳從PHP文件form.It Linux服務器無法正常工作。我希望它將它從文件所在的位置移動到子目錄'/ uploads'。上傳文件到Web服務器錯誤6 PHP

當執行echo$_FILES["file_upload"]['error'];來獲取錯誤編號時,我得到下面的錯誤。

它返回:

Upload failed with error code 6 

有誰知道這個錯誤是什麼主張?

表格代號:

<!DOCTYPE html> 
<html> 
<body> 

<form action="upload.php" method="post" enctype="multipart/form-data"> 
    Select File to upload: 
    <input type="file" name="file_upload" id="file_upload"> 
    <input type="submit" value="Upload File" name="submit"> 
</form> 

</body> 
</html> 

upload.php的:

<?php 

    if(isset($_POST['submit'])) 
    { 
     if($_FILES['file_upload']['name'] != "") 
    { 
      $target_dir = "uploads/"; 
      $target_file = $target_dir . basename($_FILES["file_upload"]["name"]); 
      $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 
      $uploadOk = 1; 
    } 
    else 
    { 
     die("No file specified!"); 
    } 

    // Check if file already exists 
    if (file_exists($target_file)) { 
     echo "Sorry, file already exists."; 
     $uploadOk = 0; 
    } 

    // Check file size 
    if ($_FILES["file_upload"]["size"] > 500000) { 
     echo "Sorry, your file is too large."; 
     $uploadOk = 0; 
    } 

    // Allow certain file formats 
    if($imageFileType != "txt" && $imageFileType != "xls" && $imageFileType != "xlsx") 
    { 
     echo "Sorry, only TXT, XLS, XLSX files are allowed."; 
     $uploadOk = 0; 
    } 

    if ($_FILES["file_upload"]['error'] !== UPLOAD_ERR_OK) { 
     die("Upload failed with error code " . $_FILES['file_upload']['error']); 
    } 
    // Check if $uploadOk is set to 0 by an error 
    if ($uploadOk == 0) { 
     echo "Sorry, your file was not uploaded."; 
    // if everything is ok, try to upload file 
    } else { 
     if (move_uploaded_file($_FILES["file_upload"]["tmp_name"], $target_file)) { 
      echo "The file ". basename($_FILES["file_upload"]["name"]). " has been uploaded."; 
     } else { 
      echo "Sorry, there was an error uploading your file."; 
     } 
    } 
    } 
    ?> 

我已經搜索這個問題,並找到解決方案Here。但不能正確的解決。

我也給予了充分的權限到/uploads文件夾。 任何幫助將不勝感激。由於

+0

你應該先搜索了problem.Possible複製http://stackoverflow.com/questions/8719244/move-uploaded-file-error-6-php – 2014-11-24 07:15:36

+0

@sgt,我已經搜索問題,但不明白這篇文章給出的解決方案。 – 2014-11-24 07:19:46

+0

它在那裏。可能你不知道設置。然後問正確的問題。 – 2014-11-24 07:23:44

回答

0

我用 「setenforce 0」 對SELinux的進入許可模式解決了這個問題;

[[email protected] tequila]# setenforce 0