Sunday, 15 September 2013

PHP CMS, When I upload the image it corrupts for some reason

PHP CMS, When I upload the image it corrupts for some reason

The image is being corrupted when uploaded to the database so i tried to
do the base64_encode but it didn't work any suggestions as to what i can
do ? its a school project and its due 2 more days hope you can help :/ thx
and appreciate the help.
<?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');
}
?>

No comments:

Post a Comment