php
1<!DOCTYPE html> 2<html lang ="en"> 3 4<body> 5<form enctype="multipart/form-data" method="POST"> 6<input type ="file" name ="userfile"> 7<input type = "submit" value="upload"> 8</form> 9</body> 10 11<?php 12 13$dir_path = './files/'; 14if (is_dir($dir_path)){ 15if(is_readable($dir_path)){ 16$ch_dir = dir($dir_path); 17 18while (false !== ($file_name = $ch_dir -> read())){ 19$ln_path = $ch_dir -> path . "/" .$file_name; 20if (@getimagesize($ln_path)){ 21echo "<a href = \"imgview.php?d=" .urlencode(mb_convert_encoding($ln_path, "UTF-8")). "\" target = \"_blank\" >"; 22echo "<img src = \"" .$ln_path. "\" width=\"100\"></a> ";}} 23$ch_dir -> close();} 24else{ 25echo "<p>" .htmlspecialchars($dir_path)." は読み込みが許可されていません。";}} 26else{ 27echo 'DIR 画像がないよ';} 28 29if(isset($_FILES["userfile"]) and $_FILES["userfile"]["error"]==0){ 30 31 $uploadDir = './files/'; 32 $uploadPath = $uploadDir . $_FILES['userfile']['name']; 33 echo "<a href = \"imgview.php?d=" .urlencode(mb_convert_encoding($ln_path, "UTF-8")). "\" target = \"_blank\" >"; 34 echo "<img src = \"" .$ln_path. "\" width=\"100\"></a> "; 35 36 if(move_uploaded_file( 37 $_FILES['userfile']['tmp_name'], 38 $uploadPath 39 )){ 40 echo '成功です'; 41 }else{ 42 echo '失敗です'; 43 } 44
このコードを実行したときに送信ボタンを押した時に選択した画像が一覧に表示されるようにするには、どうすればよいのでしょうか
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。