phpfile-uploaduploadphp-ini

upload file to web server error 6 php


I am trying to upload a file from a php form.It wont work on linux server. I want it to move it to a subdir '/uploads' from where the file is.

I get the below error when executing the page by echo the $_FILES["file_upload"]['error']; to get the error number.

It returns :

Upload failed with error code 6

Does anyone know what this error stands for?

Form Code :

<!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.";
        }
    }
    }
    ?>

I already search for this problem and find the solution Here. But not undestand properly.

I also given full permission 777 to /uploads folder. Any help will be greatly appreciated. Thanks


Solution

  • UPLOAD_ERR_NO_TMP_DIR
    
    Value: 6; Missing a temporary folder. Introduced in PHP 5.0.3.
    

    http://php.net/manual/en/features.file-upload.errors.php

    Fix your settings..

    http://php.net/manual/en/ini.core.php#ini.upload-tmp-dir