简体   繁体   中英

Size limit for file upload

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?

PS: 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?

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. ie php/wordpress default upload limit

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";
                    }

        }
    ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM