最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Size limit for file upload - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question edited Feb 19, 2015 at 13:36 Mike Mameko asked Feb 19, 2015 at 11:38 Mike MamekoMike Mameko 3191 gold badge3 silver badges11 bronze badges 2
  • stackoverflow./questions/20706418/… – pawel Commented Feb 19, 2015 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 Commented Feb 19, 2015 at 11:47
Add a ment  | 

2 Answers 2

Reset to default 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

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

        }
    ?>
发布评论

评论列表(0)

  1. 暂无评论