samedi 24 février 2018

PHP file upload error for large files

I am trying to upload files using php on my local server and save it in the current working directory.The code is working fine for any file type of size less than 2mb but above this size it gives error. I have also modified the upload and post size in php.ini file,but it was of no help.It gives 4 errors: 1-Undefined index: temp in C:\wamp64\www\project\upload.php on line 3. 2-file_get_contents(C:\wamp64\www\project\project): failed to open stream: No such file or directory in C:\wamp64\www\project\upload.php on line 5. 3-Undefined index: temp in C:\wamp64\www\project\upload.php on line 6. 4-Undefined index: temp in C:\wamp64\www\project\upload.php on line 18. I am saving the uploaded file in the same location where upload.php is located.

Upload.php:

<?php
$target_dir = getcwd();
$target_file = $target_dir .'\project'. basename($_FILES["temp"]["name"]);
$uploadOk = 1;
echo file_get_contents($target_file);
if ($_FILES["temp"]["size"] > 5000000000) 
{
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}

if ($uploadOk == 0) 
{
    echo "Sorry, your file was not uploaded.";
} 
else 
{
    if (move_uploaded_file($_FILES["temp"]["tmp_name"], $target_file)) 
    {
        echo "The file ". basename( $_FILES["temp"]["name"]). " has been 
uploaded.";
    } 
    else 
    {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>




Aucun commentaire:

Enregistrer un commentaire