php獲取遠端檔案大小

2021-06-18 23:10:00 字數 1764 閱讀 4448

獲取本地檔案大小filesize()就可以了,但是如何獲取遠端檔案的大小呢? 這裡介紹四個方法來獲取遠端檔案的大小.

方法1:get_headers

<?php 

get_headers($url,true); 

//返回結果 

此處可以直接根據content-length來獲取到遠端檔案的大小了.

方法2:curl

}方法3:fsock

function getfilesize($url) 

elseif(preg_match('/content-length:(.*)/si',$tmp,$arr))  } 

return null; 

} else  }

方法4:file_get_contents

$fcont = file_get_contents(""); 

echo strlen($fcont)/1024; 

以上四種方法

PHP 實時獲取檔案大小

要將乙個大的資料寫入檔案,但是不想寫入乙個,想寫成乙個檔案xm,就需要實時判斷檔案大小,如果不清理檔案狀態快取的話,無法實現效果。clearstatcache 函式清除檔案狀態快取。clearstatcache 函式會快取某些函式的返回資訊,以便提供更高的效能。但是有時候,比如在乙個指令碼中多次檢查...

獲取檔案大小

1 找到檔案所在的絕對路徑。系統路徑 projectpath request.getsession getservletcontext getrealpath 檔案路徑 在上傳檔案的時候,一定會有檔案相對路徑,如果不清楚,可以打斷點然後在本地找到此檔案。檔案相對路徑 filepath 絕對路徑rea...

VC獲取檔案大小

vc獲取檔案大小 我查到兩種方法 方法一 win32 find data fileinfo handle hfind dword filesize const char filename 檔案的路徑及名字 hfind findfirstfile filename fileinfo if hfind ...