Getting upload file size before upload

前端 未结 5 583
故里飘歌
故里飘歌 2020-12-20 16:07

When the user selects a file to be uploaded, is there a way I can get the exact size of this file before the upload even begins? I\'m guessing this needs to be done on the c

5条回答
  •  误落风尘
    2020-12-20 16:50

    I suggest you look at the HTML5 File API. This, combined with some JS might be able to help you. I only say might because I have not yet had a chance to browse at this part of the HTML5 standard.

    http://www.w3.org/TR/FileAPI/#dfn-filereader

    The way PHP file uploads work, it is very hard to check file details before, or during a file upload (since the file is uploaded before your code even gets loaded).

    I know it is possible to do some fancy things in some other languages (possibly Perl or Python) that handle the file uploading directly with the script (where the script opens the socket and handles the whole transfer itself), however PHP does this for you and accepts any file on your script's behalf. The file gets discarded if it is not within PHP's acceptable limits, but only after the file is completely uploaded.

    There have also been several file upload implementations made using Flash, but not being an ActionScript coder, I can't really help too much there either.

提交回复
热议问题