2010年3月2日火曜日

画像UPソース2

<?php
$img_tmp = $_FILES["img_path"]["tmp_name"];
$img_name = $_FILES["img_path"]["name"];
$img_size = $_FILES["img_path"]["size"];
if($_REQUEST["up"] != ""){

if($img_tmp != "" and $img_size <= 30000){

$img_message = "名前は: $img_name <br>サイズは: $img_size <br>MIMEタイプは: $img_type <br>一時的に保存されているパスは: $img_tmp <br>";

$FilePath = "./img/".date("Ymdhis").".".GetExt($img_name);

move_uploaded_file($img_tmp,$FilePath);

$fp = fopen("./img/data.txt","a");
fputs($fp,$FilePath."\n");
fclose($fp);
}else{
$size_error = "サイズが大きすぎます。ファイルサイズは30キロバイト以下です。";

}
}
// GetExt
// ファイルの拡張子を取得します。
function GetExt($FilePath){
$f=strrev($FilePath);
$ext=substr($f,0,strpos($f,"."));
return strrev($ext);
}
?><html>
<head>
<title>画像アップロード</title>
</head>
<body>
<h1>画像アップロード</h1>
<font color="#FF0000"><strong><?= $size_error ?></strong></font><?= $img_message ?>
<form name="form" action="<?php print $_SERVER['PHP_SELF']; ?>" method="POST"
ENCTYPE="MULTIPART/FORM-DATA">
<input name="img_path" type="file" size="40">
<input name="up" type="submit" value="アップロード"><hr>
<table border="0">
<tr>
<?php

$array_img = file("./img/data.txt");

for($i=0; $i<sizeof($array_img); $i++){

$array_img[$i] = ereg_replace("\n","",$array_img[$i]);

print "<td style=\"border:1px solid #000000\"><img src=\"$array_img[$i]\" width=\"100\" height=\"100\"></td>";
}
?>

</tr>
</table>
</form>
</body>
</html>

0 件のコメント:

コメントを投稿