오늘 저는 mp3 파일을 직접 다운로드하도록하는 PHP 스크립트를 만들고 싶습니다. 난에 배치됩니다 다운로드 할PHP 스크립트로 파일에 연결할 수 없습니다.
파일 폴더를 소리 나는 http://playall.pl/sounds/ThemadpixprojectBadChick.mp3
통해에 액세스 할 수 있습니다하지만 PHP 스크립트에 올 때 -이 파일이 서버에없는 것을 기능을 말한다 file_exists.
어떻게 해결할 수 있습니까? 파일을
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file_name));
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($file));
ob_clean();
flush();
readfile($file);
exit;
을 다운로드하고 file_exists($file)
의 전체 경로를 필요로 $file
변수에 대한 파일 이름과 파일의 URL을
$file_name = ''.$sound['Sounds']['artist'].' - '.$sound['Sounds']['title'].'.mp3';
$file_name = preg_replace('/\s+/', '_', $file_name);
$file = 'http://playall.pl'.$this->webroot.'sounds/'.$sound['Sounds']['src_url'];
브라우저를 리디렉션하지 않는 이유는 무엇입니까? –
버튼 클릭시 강제로이 파일을 다운로드하려고하기 때문에. – GamaPL
그리고 CakePHP 프레임 워크를 사용하여 메신저를 추가하십시오. – GamaPL