2014-09-30 68 views
0

我刚刚意识到只能发布大约8 MB的数据。我有一个表单来上传多个文件。这些文件通过POST方法发送到一个php页面上传。现在,我想检查将发布的数据大小并发出警报消息。我怎样才能做到这一点?我搜索了一下,发现$ _SERVER ['CONTENT_LENGTH']可以用来找到它。不幸的是,我无法弄清楚如何使用它? 这里是我的形式:如何在POST数据之前找到文件的大小?

<form name="offer" onsubmit="return validateForm()" action="fileupload.php" method="post" enctype="multipart/form-data"> 
     <tr> 
     <td>I9:</td> 
     <td> Doc: <input type="file" id="myfile" name="myfile[]"><p id="list"></p></td> 
    </tr> 
    <tr > 
     <td>Client document: </td> 
     <td> Doc: <input type="file" id="myfile" name="myfile[]"></td> 
    </tr> 
     <tr> 
     <td>FCRA :</td> 
     <td> Doc: <input type="file" id="myfile" name="myfile[]"></td> 
     </tr> 
     <tr> 
     <td>Insurance Certificate :</td> 
     <td> Doc: <input type="file" id="myfile" name="myfile[]"></td> 
     </tr> 
     <tr> 
     <td>Work Order :</td> 
     <td> Doc: <input type="file" id="myfile" name="myfile[]"></td> 
     </tr> 

而且,是可以显示每个上传文件的大小?我知道这可以通过JavaScript来完成。但是如何?

+0

为什么不修改php.ini允许更大上传? – 2014-09-30 20:45:50

+0

http://stackoverflow.com/questions/1606842/how-can-i-get-a-files-upload-size-using-simple-javascript - 顶级投票答案在这里是好/简单 – eselk 2014-09-30 20:46:01

+0

也:http:/ /stackoverflow.com/questions/7497404/get-file-size-before-uploading http://stackoverflow.com/questions/3717793/javascript-file-upload-size-validation – eselk 2014-09-30 20:46:30

回答

-2

时使用此客户端

function findSize() { 
    var fileInput = document.getElementById("_ufile_1"); 
    try{ 
     alert(fileInput.files[0].size); // Size returned in bytes. 
    }catch(e){ 
     var objFSO = new ActiveXObject("Scripting.FileSystemObject"); 
     var e = objFSO.getFile(fileInput.value); 
     var fileSize = e.size; 
     alert(fileSize);  
    } 
} 
+0

使用此功能 – 2014-09-30 21:10:42

相关问题