2012-10-05 26 views
0

我想獲取圖像的文件大小。如果我上傳5 MB大小的圖像,則此功能正確計算圖像大小。但是,如果超過圖像文件大小,那麼它不是計算圖像文件!圖像文件大小在Php

$ size = filesize($ _ FILES ['file'] ['tmp_name']);

我不明白問題是什麼。

+2

檢查先看到你的file_exists(),櫃面還沒有上傳正確 – bumperbox

+3

如果超過uploadsize,該文件是不是在服務器上實際可用。 –

+0

除了最大尺寸限制外(這可能是你遇到的問題),'$ _FILES'數組已經在'size'條目中包含了文件大小;沒有必要自己調用'filesize'。 –

回答

0

未經測試的代碼

if(empty($_FILES) && empty($_POST) && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post'){ //catch file overload error... 
     $postMax = ini_get('post_max_size'); //grab the size limits... 
     echo "<p style=\"color: #F00;\">\nPlease note files larger than {$postMax} will result in this error!<br>Please be advised this is not a limitation in the CMS, This is a limitation of the hosting server. 
     callMyForm(); //bounce back to the just filled out form. 
} 
elseif(// continue on with processing of the page... 
+1

找到一些帖子....檢查這個http://stackoverflow.com/questions/2133652/how-to-gracefully-handle-files-that-exceed-phps-post-max-size – mymotherland