2012-06-07 2 views
1

그래서 내 사이트에 호스팅되어있는 경우 사용자가 버튼을 클릭하여 이미지를 다운로드 할 수 있도록 설정했지만 외부 이미지에는 사용할 수 없습니다. 서버의 폴더에 먼저 복사하지 않고 외부 이미지 (URL 사용)로이 작업을 수행 할 수 있습니까?사용자가 외부 이미지를 다운로드 할 수있게 허용 PHP

이것은 내 사이트의 이미지에 사용하는 것입니다.

$str = $_GET['image']; 
$img_name = substr(strrchr($str, '/'), 1); 
$image = "../u/i/".$img_name; 

if (file_exists($image)) { 
    header('Content-Description: File Transfer'); 
    header('Content-Type: application/octet-stream'); 
    header('Content-Disposition: attachment; filename='.basename($image)); 
    header('Content-Transfer-Encoding: binary'); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
    header('Pragma: public'); 
    header('Content-Length: ' . filesize($image)); 
    ob_clean(); 
    flush(); 
    readfile($image); 
    exit(); 
} 

도움을 주시면 감사하겠습니다.

답변

1

http://php.net/manual/en/function.readfile.php에서 볼 수 있듯이 외부 URL을 사용할 수 있습니다.

fopen wrappers을 사용하는 경우이 기능을 사용하면 URL을 파일 이름으로 사용할 수 있습니다. 의 파일 이름 지정 방법에 대한 자세한 내용은 fopen()을 참조하십시오. 다양한 랩퍼의 기능에 대한 정보로의 연결에 대해서는 의 Supported Protocols and Wrappers을 참조하십시오. 노트의 사용법에 대한 정보 및 에서 제공 할 수있는 미리 정의 된 변수에 대한 정보를 참조하십시오.

그것은 PHP 설정입니다 : (. 코드는 다음 변경이 필요하지 않습니다) http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

관련 문제