0

フォルダーからファイルを読み取る php でファイル名リーダーを作成しました。今度は、このファイルを webreader からダウンロードする機能を追加し、保存する場所を選択できるようにします。

スクリプトの何が問題なのか本当にわかりません。

アイデアを持っている人はいますか?これは私が現時点で持っているものです。

index.php

<?php
$mydir = "images/";
if ($handle = opendir($mydir)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != '.' && $file != '..') {
?>
           <a href="download.php?f=<?php echo $file ?>" target="_blank"><?php echo $file ?></a>
<?php
        }
    }
    closedir($handle);
}
?>

ダウンロード.php

<?php $filename = $_GET['f'];
// set this to the path where your zipped files are located
$filepath = "images" . $filename;
// a little security
if(strpos($filename, '..') !== false || realpath($filepath) != $filepath) die();
if (file_exists($filepath)){
    // make sure the browser knows what it's getting, and what to do with it
    header('Cache-Control: public');
    header('Content-Type: application/zip');
    header('Content-Disposition: attachment; filename=' . $filename);
    readfile($filepath);
    die(); 
} else {
    die('Error: File not found.');
}

?>
4

1 に答える 1

0

$filepath = "images/" . $filename;代わりに試してください$filepath = "images" . $filename;

于 2012-05-12T10:17:43.697 に答える