2012-10-25 4 views
0

여기 내 코드는,사용자가 모바일 갤러리로 이미지를 어떻게 다운로드 할 수 있습니까?

<?php 
$file_name = "coupon.png"; 
$file_path = $_GET['path']; 
$file_size = filesize($file_path); 
header('Pragma: public'); 
header('Expires: 0'); 
header('Last-Modified: ' . gmdate('D, d M Y H:i ') . ' GMT'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Cache-Control: private', false); 
header('Content-Type: application/octet-stream'); 
header('Content-Length: ' . $file_size); 
header('Content-Disposition: attachment; filename="' . $file_name . '";'); 
header('Content-Transfer-Encoding: binary'); 
readfile($file_path); 
?> 

P.S. $_GET['path'] 이미지 경로 URL

PC의 브라우저에서 원활하게 실행할 수 있습니다. 그러나 사용자가 모바일 브라우저를 사용하여 다운로드하면 새 웹 페이지 탭이 표시됩니다.

사용자가 이미지를 다운로드하여 모바일 갤러리에 자동으로 저장할 수있는 방법이 있습니까?

답변

0

는 다음과 같이하십시오 :

<?php 
$file_name = "coupon.png"; 
$file_path = $_GET['path']; 
$file_size = filesize($file_path); 
header('Pragma: public'); 
header('Expires: 0'); 
header('Last-Modified: ' . gmdate('D, d M Y H:i ') . ' GMT'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Cache-Control: private', false); 
header('Content-Type: application/force-download'); // Browser cant identifiy the type. so it will force to download 
header('Content-Length: ' . $file_size); 
header('Content-Disposition: attachment; filename="' . $file_name . '";'); 
header('Content-Transfer-Encoding: binary'); 
readfile($file_path); 
?> 

모바일 브라우저가 파일을 여는 방법을 모르는, 그래서 다운로드 강제 때문에

.

+0

여전히 새 웹 페이지 탭을 표시하지만 감사합니다. –

관련 문제