0
將圖像上傳到sql數據庫我試圖創建一個AdLister網站 - 到目前爲止用戶發佈到數據庫中的所有內容都會在網站上正確顯示,除了圖像。下面是我的代碼 - 請讓我知道如果我留下什麼東西了:如何通過php
$insert_table = "INSERT INTO posts (userid, post_date, title, price, description, email, location, image) VALUES (:userid, :post_date, :title, :price, :description, :email, :location, :image)";
$stmt = $dbc->prepare($insert_table);
$stmt->bindValue(':userid', 1, PDO::PARAM_STR);
$stmt->bindValue(':post_date', $date, PDO::PARAM_STR);
$stmt->bindValue(':title', $title, PDO::PARAM_STR);
$stmt->bindValue(':price', $price, PDO::PARAM_STR);
$stmt->bindValue(':description', $description, PDO::PARAM_STR);
$stmt->bindValue(':email', $email, PDO::PARAM_STR);
$stmt->bindValue(':location', $location, PDO::PARAM_STR);
$stmt->bindValue(':image', $image, PDO::PARAM_STR);
$stmt->execute();
return $errors;
}
if (!empty($_POST)) {
if (checkValues()) {
$errors = insertPost($dbc);
} else {
$message = "Invalid format. Please try again.";
$javascript = "<script type='text/javascript'>alert('$message');</script>";
echo $javascript;
}
}
if(Input::has('title')){
if($_FILES) {
$uploads_directory = '/img';
$filename = $uploads_directory . basename($_FILES['image']['name']);
if (move_uploaded_file($_FILES['image']['tmp_name'], $filename)) {
// echo '<p>The file '. basename($_FILES['image']['name']). ' has been uploaded.</p>';
} else {
//alert("Sorry, there was an error uploading your file.");
}
}
}
<table class="table table-hover table-bordered table-striped">
<tr class='table-hover'>
<th class="header">Photo</th>
<th class="header col-md-1">Date Posted</th>
<th class="header">Title</th>
<th class="header col-md-1">Price</th>
<th class="header col-md-6">Description</th>
<th class="header col-md-6">Image</th>
</tr>
<?php
foreach ($posts as $post):?>
<tr class='table table-hover table-bordered body'>
<td>Photo</td>
<td><?= $post['post_date'] ?></td>
<td><?= $post['title']?></td>
<td><?= $post['price']?></td>
<td><?= $post['description']?></td>
<td><?= $post['image']?></td>
<?php endforeach ?>
</tr>
</table>
http://php.net/manual/en/function.error-reporting.php –