写一个PHP大作业,包含5个网页,3个嵌套表格,上传文件和在线相册的代码
时间: 2024-03-08 14:50:23 浏览: 55
好的,以下是一个简单的PHP大作业的源代码,包括5个网页,3个嵌套表格,上传文件和在线相册。请确保您已经创建了一个名为“uploads”的文件夹,以便上传文件保存在其中。
1. 首页(index.php)
```php
<!DOCTYPE html>
<html>
<head>
<title>首页</title>
</head>
<body>
<h1>欢迎来到我的网站</h1>
<p>请点击以下链接访问其他页面:</p>
<ul>
<li><a href="upload.php">上传文件</a></li>
<li><a href="gallery.php">在线相册</a></li>
<li><a href="about.php">关于我们</a></li>
<li><a href="contact.php">联系我们</a></li>
</ul>
</body>
</html>
```
2. 上传文件(upload.php)
```php
<!DOCTYPE html>
<html>
<head>
<title>上传文件</title>
</head>
<body>
<h1>上传文件</h1>
<?php
if(isset($_POST['submit'])){
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
if(move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)){
echo "文件已上传成功!";
echo "<br><a href='".$target_file."' download>下载文件</a>";
}
else{
echo "上传文件失败。";
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<label>选择文件:</label>
<input type="file" name="fileToUpload" required><br><br>
<input type="submit" name="submit" value="上传">
</form>
</body>
</html>
```
3. 在线相册(gallery.php)
```php
<!DOCTYPE html>
<html>
<head>
<title>在线相册</title>
</head>
<body>
<h1>在线相册</h1>
<?php
$dir = "uploads/";
$files = scandir($dir);
foreach($files as $file){
if(in_array($file, array(".",".."))) continue;
echo "<table><tr>";
echo "<td><a href='".$dir.$file."' target='_blank'><img src='".$dir.$file."' height='100'></a></td>";
echo "</tr></table>";
}
?>
</body>
</html>
```
4. 关于我们(about.php)
```php
<!DOCTYPE html>
<html>
<head>
<title>关于我们</title>
<style>
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
padding: 5px;
}
</style>
</head>
<body>
<h1>关于我们</h1>
<p>我们是一支充满热情的团队,致力于为用户提供最好的服务。</p>
<table>
<tr>
<th>姓名</th>
<th>职位</th>
<th>联系方式</th>
</tr>
<tr>
<td>张三</td>
<td>CEO</td>
<td>zhangsan@abc.com</td>
</tr>
<tr>
<td>李四</td>
<td>CTO</td>
<td>lisi@abc.com</td>
</tr>
<tr>
<td>王五</td>
<td>COO</td>
<td>wangwu@abc.com</td>
</tr>
</table>
</body>
</html>
```
5. 联系我们(contact.php)
```php
<!DOCTYPE html>
<html>
<head>
<title>联系我们</title>
<style>
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
padding: 5px;
}
</style>
</head>
<body>
<h1>联系我们</h1>
<?php
if(isset($_POST['submit'])){
$to = "admin@abc.com";
$subject = "网站联系表单提交";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers = "From: ".$name." <".$email.">";
if(mail($to, $subject, $message, $headers)){
echo "您的消息已经成功发送!";
}
else{
echo "发送消息时出现错误,请重试。";
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<table>
<tr>
<td><label>姓名:</label></td>
<td><input type="text" name="name" required></td>
</tr>
<tr>
<td><label>电子邮件:</label></td>
<td><input type="email" name="email" required></td>
</tr>
<tr>
<td><label>消息:</label></td>
<td><textarea name="message" required></textarea></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="发送"></td>
</tr>
</table>
</form>
</body>
</html>
```
阅读全文