[PHP] 纯文本查看 复制代码 <?php
session_start();
?>
<?php
include_once 'Nav.php';
$inv_date = date("Y-m-d");
if(isset($_POST['submit'])) {
$imgUrl = uploadImage(); // 上传图片并获取图片地址
if($imgUrl) {
// 进行数据库录入操作
// ...
} else {
echo "图片上传失败";
}
}
function uploadImage() {
$targetDir = "uploads/"; // 图片保存目录
$targetFile = $targetDir . basename($_FILES['image']['name']); // 图片保存路径
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));
// 检查文件是否为真正的图片
if(isset($_POST['submit'])) {
$check = getimagesize($_FILES['image']['tmp_name']);
if($check !== false) {
$uploadOk = 1;
} else {
$uploadOk = 0;
}
}
// 检查文件是否已存在
if(file_exists($targetFile)) {
$uploadOk = 0;
}
// 检查文件大小
if($_FILES['image']['size'] > 500000) {
$uploadOk = 0;
}
// 限制文件类型
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg") {
$uploadOk = 0;
}
// 如果没有错误,上传文件
if($uploadOk == 1) {
if(move_uploaded_file($_FILES['image']['tmp_name'], $targetFile)) {
return $targetFile;
} else {
return false;
}
} else {
return false;
}
}
?>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<h4 class="header-title mb-3 size_18">新增图片</h4>
<form class="needs-validation" action="" method="post" onsubmit="return check()" enctype="multipart/form-data"
novalidate>
<div class="form-group mb-3">
<label for="validationCustom01">日期</label>
<input class="form-control col-sm-4" id="example-date" type="date" name="imgDatd" class="form-control" placeholder="日期" value="<?php echo $inv_date ?>" required>
</div>
<div class="form-group mb-3">
<label for="validationCustom01">图片描述<span class="margin_left badge badge-success-lighten">尽量控制在25个字符以内 </span></label>
<input name="imgText" type="text" class="form-control" placeholder="请输入图片描述" value="" required>
</div>
<div class="form-group mb-3">
<label for="validationCustom01">上传图片</label>
<input type="file" name="image" class="form-control" required>
</div>
<div class="form-group mb-3 text_right">
<button class="btn btn-primary" type="submit" name="submit">新增相册</button>
</div>
</form>
</div> <!-- end card-body-->
</div> <!-- end card-->
</div> <!-- end col-->
</div>
<script>
function check() {
let title = document.getElementsByName('imgText')[0].value.trim();
if (title.length == 0) {
alert("事件不能为空");
return false;
}
}
</script>
<?php
include_once 'Footer.php';
?>
</body>
</html> |