5

I investigate the problem of file upload using html5, and I have theoretical question: has html5 any limits for file size for uploading? For example, can I upload files with size ~500Gb?

P.S.: I use FileReader api for reading file.

Ok. This problem is resolved.

But as it explains in FileReader API:

This interface provides methods to read File objects or Blob objects into memory...

As I understood correctly, I can't read file with size which is more than available RAM?

Mike Mameko
  • 199
  • 1
  • 2
  • 11
  • http://stackoverflow.com/questions/20706418/are-there-file-size-limitations-when-using-javascript-filereader-api – pawel Feb 19 '15 at 11:45
  • @pawel I also saw that and was going to flag as duplicate, but as it not got a answer it wouldn't allow it. It's a shame answer's can't be voted upon – atmd Feb 19 '15 at 11:47

2 Answers2

6

Nope, there is no size upload limit.

here is the spec and here is a related question on how to check the file size, so that you can add limits if you like.

It's worth pointing out that if you are looking to store the file on the server, you might hit file upload limits/restrictions there. But you should be able to configure them. i.e. php/wordpress default upload limit

Community
  • 1
  • 1
atmd
  • 7,430
  • 2
  • 33
  • 64
  • And can I ask another question: can we read file partially? If we have file with size 300Gb, does it can be read into memory? – Mike Mameko Feb 19 '15 at 12:02
  • By partially, do you mean, read a section (say half) of a file, or read a file in chucks rather then in one go? My understanding from the spec (although I might be wrong) is that a file ***is*** read in chunks. Not sure Re: memory. I know the browser storage limit is less then available ram, but thats about my limit – atmd Feb 19 '15 at 12:08
  • Yes, I mean to read file in chucks, for example 10Mb... It is impossible to read file by FileReader if file has size more than available ram...and, maybe, it could be solution, to upload files in chucks for so large files – Mike Mameko Feb 19 '15 at 12:18
0

Hope this useful..

Form,script for validating:

<form action="check.php" method="post" enctype="multipart/form-data">
<label>Upload An Image</label>
<input type="file" id="file_upload" name="file_upload" />
<input type="submit" onClick="return validate()" name="upload"/>
</form>

<script>
function validate(){
var size=2097152;
var file_size=document.getElementById('file_upload').files[0].size;
if(file_size>=size){
    alert('File too large');
    return false;
}
var type='image/jpeg';
var file_type=document.getElementById('file_upload').files[0].type;
if(file_type!=type){
    alert('Format not supported,Only .jpeg images are accepted');
    return false;
}
}

php for uploading:

 <?php 
        if(isset($_POST['upload'])){

                $target_dir = "uploads/";
                $target_file = $target_dir . basename($_FILES["file_upload"]["name"]);
                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";
                    }

        }
    ?>