0
A
답변
1
$sz = 0;
$dir = '/tmp'; // will find largest for `/tmp`
if ($handle = opendir($dir)) { // will iterate through $dir
while (false !== ($entry = readdir($handle))) {
if(($curr = filesize($dir . '/' . $entry)) > $sz) { // found larger!
$sz = $curr;
$name = $entry;
}
}
}
echo $dir . '/' . $name; // largest
1
$dir = 'DIR_NAME';
$max_filesize = 0;
$path= '';
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(realpath($dir),FilesystemIterator::SKIP_DOTS)) as $file){
if ($file->getSize() >= $max_filesize){
$max_filesize = $file->getSize();
$path = $file->getRealPath(); // get absolute path
}
}
echo $path;
0
function getFileSize($directory) {
$files = array();
foreach (glob($directory. '*.*') as $file) {
$files[] = array('path' => $file, 'size' => filesize($file));
}
return $files;
}
function getMaxFile($files) {
$maxSize = 0;
$maxIndex = -1;
for ($i = 0; $i < count($files); $i++) {
if ($files[$i]['size'] > $maxSize) {
$maxSize = max($maxSize, $files[$i]['size']);
$maxIndex = $i;
}
}
return $maxIndex;
}
사용 :
$dir = '/some/path';
$files = getFileSize($dir);
echo '<pre>';
print_r($files);
echo '</pre>';
$maxIndex = getMaxFile($files);
var_dump($files[$maxIndex]);
관련 문제
- 1. PHP 절대 경로 requireonce
- 2. 절대 경로가있는 PHP file_put_contents?
- 3. PHP 스크립트 절대 경로
- 4. PHP : localhost 포함의 절대 경로
- 5. 파일 클래스는 절대 경로
- 6. 절대 경로에서 파일 다운로드
- 7. 절대 경로에서 파일 삭제
- 8. 은 절대 파일 경로가
- 9. Joomla 2.5에있는 파일 디렉토리 목록에 대한 절대 PHP URL 얻기
- 10. PHP - 절대 URL의 상대 URL
- 11. 업로드 및 절대 파일 경로?
- 12. strace의 절대 파일 경로 만?
- 13. 골란에서 절대 파일 경로 설정
- 14. mod_rewrite의 절대 파일 경로가 허용됩니까?
- 15. 위치 절대 div가 PDF 파일
- 16. Clojure에서 절대 위치에 파일 열기
- 17. 파일 다운로드은 iframe 상대 대 절대 주소
- 18. PHP 웹 사이트의 절대 URL 경로
- 19. PHP 함수 앵커 태그의 절대 경로
- 20. Plesk의 PHP - 절대 디렉토리를 볼 수 없습니다.
- 21. 상대 시간 대 절대 시간이 PHP
- 22. php : 절대 URL에있는 모든 상대 URL을 변환하십시오.
- 23. PHP 주석 - 클래스의 절대 이름 얻기
- 24. PHP : 텍스트 영역의 절대 URL 대체
- 25. 일부 php + HTML에 절대 URL 추가
- 26. PHP, MoDX : PHP 스 니펫에서 파일 업로드
- 27. Git을 통해 절대 커밋되지 않을 파일 관리하기
- 28. 절대 파일 경로에서 CommonsMultipartFile을 만드는 방법은 무엇입니까?
- 29. html/javascript에서 절대 파일 경로 가져 오기
- 30. 절대 경로 가져 오기 및 파일 이동