0
votes

Im trying to upload a file to wamp server and is_upload_file returns false for for files over 10mb. Everything work fine for smaller files.

HTML

<button  type = "button" id = "uploadbutton">Click</button>
<form id = "fileupload">
    <input type="file" name = "uploadfile" id = "uploadfile" style="position: fixed; top: -100em; display:none">
</form>

js

var uploadbutton = document.getElementById("uploadbutton");
var uploadFileInput = document.getElementById("uploadfile");

uploadbutton.onclick = function()
{
    uploadFileInput.click();
};

uploadFileInput.onchange = function()
{
    onSubmitFile();
};

function onSubmitFile()
{
    console.log("onsubmitform");
    var fd = new FormData(document.getElementById("fileupload"))

    $.ajax({
        url: "uploadfile.php",
        type: "POST",
        data: fd,
        enctype: 'multipart/form-data',
        processData: false,  
        contentType: false
    }).done(function( data ) {
        alert(data);
    });
}

PHP

if (is_uploaded_file($_FILES["uploadfile"]["tmp_name"]))
{
    $name = $_FILES["uploadfile"]["name"];
    move_uploaded_file($_FILES["uploadfile"]["tmp_name"], "C:\\$name");
    echo $_FILES["uploadfile"]["name"];
    echo "File uploaded";
}
else
{
    echo "File not uploaded";
}
print_r($_FILES);

print_r($_FILES) prints an empty array when is_uploaded_file fails.

in php.ini

upload_max_filesize 64M post_max_size 20M max_input_time 300 max_execution_time 300

5
Refer this: sitepoint.com/upload-large-files-in-php Also note display : none may trouble you in mobile devices. If you want to hide it then set width and height to 0pxRayon
@rahul, It would be helpful if the concern would be IT DOES NOT WORK, but in this case, it does not work only if file is large.Rayon
Are you using Wampserver ?Rayon
(left click ) wampmanager icon -> PHP -> php.ini this is the way you are accessing it ? Also check phpinfo()Rayon

5 Answers

2
votes

Please update below variables settings in php.ini file then try or make the changes in the ini file and restart your server

ini_set('post_max_size', '50M');
ini_set('upload_max_filesize', '50M');
2
votes

Please update below variables settings in php.ini file then try.

set_time_limit(0);
ini_set('post_max_size', '50M');
ini_set('upload_max_filesize', '50M');

Thanks

2
votes

it turns out i was editing the wrong php.ini. i edited the ini in Apache folder and everything works fine.

1
votes

Update below variables settings then try..

ini_set('post_max_size', '50M');
ini_set('upload_max_filesize', '50M');
ini_set('max_execution_time', 1200); // 1200 seconds i.e. 20 minutes
1
votes

Your Form Should look like this:

   <form action="formprocess.php" id='fileupload' method="post" enctype="multipart/form-data">