2016-08-31 2 views
1

: 파일이 /temp 폴더에 저장하고 호기심 것입니다PHP 다운로드 일부 빈 파일 나는 서버에서 Zip 파일을 다운로드 할 수있는 코드가 일부 일반적으로

<?php 
$path_parts = pathinfo($_GET['a']); 
$file_name = $path_parts['basename']; 
$file_path = 'temp/' . $file_name; 

if (file_exists($file_path)) { 
    $size = filesize($file_path); 

    header('Cache-Control: must-revalidate'); 
    header('Pragma: public'); 
    header("Content-Description: File Transfer"); 
    header("Content-Disposition: attachment; filename=$file_name"); 
    header('Expires: 0'); 
    header("Content-Type: application/zip"); 
    header("Content-length: $size"); 
    header("Content-Transfer-Encoding: binary"); 

    // read the file from disk 
    readfile($file_path); 
} 

else 
    echo 'File does not exists'; 
?> 

을 그 나는 TXT를 다운로드하는 경우 파일을 입력하면 OK,하지만 파일이 ZIP이면 빈 파일이 다운로드됩니다. 의 파일을 의 확장자로 변경하더라도 여전히 빈 파일이 다운로드되지만 다른 파일은 정상적으로 다운로드됩니다. 이 문제의 원인은 무엇입니까?

사실, 다른 파일은 다운로드하지만 폴더에는 ZIP 파일이 다운로드됩니다.

답변

0

확장자가 아닌 파일 크기 일 수 있습니다. php.ini 파일을보고이 값들이 무엇으로 설정되어 있는지보십시오. 파일이 이보다 큰 경우 설명하면됩니다.

post_max_size=5M 
upload_max_filesize=5M 
-1

시도는 PHP가 그들을 생산하는 자바 응용 프로그램에 의해 생성 된 ZIP 파일을 읽을되지 않는 문제가

header("Content-type: application/octet-stream"); 

대신

header("Content-Type: application/zip"); 
+0

나는 방금'TXT','JAR' 파일과 다른 파일을 다운로드했지만'ZIP' 파일은 모두 비어 있습니다. –