上传到数据库时图像已损坏,所以我尝试执行 base64_encode,但它对我能做什么没有任何建议?这是一个学校项目,还有 2 天到期,希望您能提供帮助:/ thx 并感谢您的帮助。
<?php
session_start();
include_once('../includes/connection.php');
if(isset($_SESSION['logged_in'])){
if(isset($_POST['title'], $_POST['content'], $_POST['image'] )){
$title = $_POST['title'];
$image = $_POST['image'];
$image = base64_encode($image);
$content = nl2br($_POST['content']);
if(empty($title) or empty($content) or empty($content)){
$error = 'All fields are required';
} else{
$query = $pdo->prepare('INSERT INTO articles (article_title, article_content, picture_upload) VALUES (?, ?, ?)');
$query->bindValue(1, $title);
$query->bindValue(2, $content);
$query->bindValue(3, $image);
$query->execute();
header('Location: index.php');
}
}
?>
<html>
<head>
<title>CMS</title>
<link rel="stylesheet" href="../assets/style.css"
</head>
<body>
<div class="container">
<a href="index.php" id="logo">CMS</a>
<br />
<h4>Add Article</h4>
<?php if(isset($error)){ ?>
<small style="color:#aa0000;"><?php echo $error;?> </small>
<?php } ?>
<br /><br />
<form action="add.php" method="post" autocomplete="off">
<input type="text" name="title" placeholder="Title" />
<br /><br /> <input type="file" name="image" id="file"><br><br />
<textarea rows="15" cols="50" placeholder="Content" name="content"></textarea>
<input type="submit" value="Submit Article" />
</form>
</div>
</body>
<?php
} else{
header('Location index.php');
}
?>