2014-11-24 77 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