2014-11-19 2 views
0
<?php 
// force to download a file 
if(isset($_POST['download'])){ 
    $file = "images/dansyo_logo.png"; 
    header("Pragma: public"); 
    header("Expires: 0"); 
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
    header("Content-Type: application/force-download"); 
    header("Content-Disposition: attachment; filename=".basename($file)); 
    header("Content-Description: File Transfer"); 
    @readfile($file); 
    if(@readfile($file)){ 
     echo'proceed'; 
    }else{ 
     echo'failded'; 
    } 
} 
?> 

<form method='post'> 
    <button name='download'>download</button> 
</form> 

위 코드를 사용하면 파일을 다운로드 할 수 있고 동시에 데이터베이스에 값을 삽입 할 수 있습니다. 코드가 제대로 작동하고 있습니다. 파일을 다운로드 할 수 있습니다. 그러나 파일을 다운로드하거나 다운로드 한 후 아무 것도 울리지 않습니다.파일을 다운로드하고 데이터베이스에 값을 삽입하십시오.

+0

헤더 보내기 전에 원하는대로 수행하십시오. –

답변

1

헤더 다운로드 브라우저로 파일을 전송하기 때문에 당신이 헤더는

$file = "images/dansyo_logo.png"; 

//Do your DB update here, before the header 
if(is_readable($file)) { 
    // insert into database 
} else { 
    exit(basename($file)." not found."); 
} 

header("Pragma: public"); 
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Content-Type: application/force-download"); 
header("Content-Disposition: attachment; filename=".basename($file)); 
header("Content-Description: File Transfer"); 
@readfile($file); 
exit(); 

참고 전송하기 전에 그냥 해 db 제출 어떤 종류의 일을하고 싶다면, 에코하지 않을 그것 : file_exists() 사실에 돌아갑니다 디렉토리.

+0

좋아요 정말 고마워요 –

+0

Sanqueib 안녕하세요, 저는 당신의 개념을 시도하지만, 우려, 그것은 작동합니다, 업데이트 된 코드를 시도 정의되지 않은 기능 –

+0

자사 내 PC 작업 – Saqueib

관련 문제