2014-09-30 51 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

相關問題