<html>
<head>
<title>虾米大王的演示相册</title>
<style type="text/css">
body{ margin:0;padding:0;background-color: #efefef;font-size: 12px;}
ul{margin: 0;padding: 0;list-style: none;}
a{color: #333333;text-decoration: none;}
a:hover{color: #999999;}
.shrimpking_album{width: 98%;margin-left: 10px; margin-top: 10px;}
.shrimpking_album img{margin: 4px;border: 1px solid #cccccc;}
.shrimpking_album li{float: left;width: 180px;text-align: center;margin: 5px;}
</style>
<body>
<form action=" " method="post" enctype="multipart/form-data" name="form1" id="form1">
<label for="img_name">上传图片</label><input type="file" name="img_name" id="img_name">
<input type="submit" name="submit" id="submit" value="上传">
<input type="hidden" name="action1" id="action1" value="upload">
</form>
<?php
$album_name = 'shrimpking';
if(is_dir($album_name) !== true)
{
mkdir($album_name);
}
if(@ $_POST['action1'] == 'upload')
{
if(isset($_FILES['img_name']['tmp_name']))
{
$file_up = $_FILES['img_name']['name'];
$path = $album_name."/".$file_up;
if(move_uploaded_file($_FILES['img_name']['tmp_name'],$path))
{
echo "文件上传成功!<br>";
}
else
{
echo "文件上传失败!<br>";
}
}
}
?>
<hr>
<div class="shrimpking_album">
<ul>
<?php
$full_path = $_SERVER['DOCUMENT_ROOT'].'\\'.$album_name;
$dh = dir($full_path);
echo "相册目录:".$dh->path."<br>";
while(false !== ($file_name = $dh->read()))
{
if($file_name == '.' || $file_name == '..')
{
continue;
}
else
{
$path = $album_name."/".$file_name; //相对路径较好
echo "<li><a href='$path' target='_blank'><img src='$path'
width='160' height='120' border='0'><br>{$file_name}</a></li>";
}
}
$dh->close();
?>
</ul>
</div>
<br>
</body>
</html>