下記のコードだと、
リンクをクリックすると下記のようなエラーメッセージが表示されます。
Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\php10\lesson28\download.php on line 6
自分では間違いが見つけられなかったのですが、どこが間違っていますでしょうか。
2個目のphpファイルがdownload.php です。
lang
1<?php require_once '../Encode.php'; ?> 2<!DOCTYPE html> 3<html> 4<head> 5<meta charset="UTF-8" /> 6<title>PHP入門教室</title> 7</head> 8<body> 9<h3>ファイルリスト</h3> 10<table border="1"> 11<tr> 12 <th>ファイル</th><th>サイズ</th><th>最終アクセス日</th><th>最終更新日</th> 13</tr> 14<?php 15const DOC_ROOT = '../doc/'; 16clearstatcache(); 17$o_dir = @opendir(DOC_ROOT) 18 or die('フォルダが開けませんでした。'); 19while ($file = readdir($o_dir)) { 20 if (is_file(DOC_ROOT.$file)) { 21 $path = DOC_ROOT.$file; 22 $file = mb_convert_encoding($file, 'UTF-8', 'SJIS-WIN'); 23?> 24 <tr> 25 <!--/* ここからダウンロードリンクの準備 */ --> 26 <td><a href="download.php?path=<?php print(urlencode($file)); ?>"> 27 <?php print(e($file)); ?></a></td> 28 <!-- /* ここまでダウンロードリンクの準備 */--> 29 <td><?php print(round(filesize($path) / 1024)); ?>KB</td> 30 <td><?php print(date('Y/m/d H:i:s', fileatime($path))); ?></td> 31 <td><?php print(date('Y/m/d H:i:s', filemtime($path))); ?></td> 32 </tr> 33<?php 34 } 35} 36closedir($o_dir); 37?> 38</table> 39</body> 40</html>
lang
1<?php 2const DOC_ROOT = '../doc/'; 3$flag = FALSE; 4$o_dir = opendir(DOC_ROOT); 5/* ここから--クエリ情報pathのチェック-- */ 6while ($file = readdir($o_dir)) { 7 if (is_file(DOC_ROOT.$file)) { 8 $filename = $file; 9 $path = DOC_ROOT.$file; 10 $file = mb_convert_encoding($file, 'UTF-8', 'SJIS-WIN'); 11 if ($_GET['path'] === $file) { 12 $flag = TRUE; 13 break; 14 } 15 } 16} 17closedir($o_dir); 18/* ここまで--クエリ情報pathのチェック-- */ 19if (!$flag) { die('不正なパスが指定されました。'); } 20/* ↑エラー時は強制終了 */ 21/* ここから--ダウンロード処理-- */ 22header('Content-Type: application/contet-stream'); 23header('Content-Disposition: attachment;filename='.$filename); 24print(file_get_contents($path)); 25
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/07/02 07:08