2017-08-25 9 views
0

mssqlサーバーとCIを使用して、特定のフォルダーにdbファイルを自動バックアップします。これにより、サーバーからローカルコンピューターにファイルをダウンロードさせる必要があります。ユーザーがサーバーからファイルをダウンロードできるようにするには

$filename = basename($_GET['file']); 
    // Specify file path. 
    $path = 'backups/hello.txt'; 
    $download_file = $path.$filename; 

    if(!empty($filename)){ 
     // Check file is exists on given path. 
     if(file_exists($download_file)) 
     { 
     header('Content-Disposition: attachment; filename=' . $filename); 
     readfile($download_file); 
     exit; 
     } 
     else 
     { 
     echo 'File does not exists on given path'; 
     } 
    } 
} 

私はこれを試しましたが、ファイルは不明です。

+0

のように試すことができますPHPのドキュメントを1として、私はそれが '$パス= 'バックアップ/' されるべきだと思います;'。 – Spectarion

+0

@Spectarion メッセージ:未定義のインデックス:ファイル – cks

+0

訪問中のリンクを表示してください。 – Spectarion

答えて

0

、あなたがこの

download.php

if (file_exists($file)) { 
    header('Content-Description: File Transfer'); 
    header('Content-Type: application/octet-stream');//change your extension of your files 
    header('Content-Disposition: attachment; filename="'.basename($file).'"'); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate'); 
    header('Pragma: public'); 
    header('Content-Length: ' . filesize($file)); 
    readfile($file); 
    exit; 
    } 
+0

$ file ??????? A PHPエラーが 重要度を発生しました:未定義の変数: メッセージに注意してください – cks

+0

$ファイルをファイルをファイル「バックアップ/ hello.txt」を使用してファイルの場所です – Robert

関連する問題