我對PHP很陌生,試圖將圖像上傳到服務器,然後使用表單和php使用下面的代碼和表單將其寫入數據庫,但它似乎不是工作,如果我把所有的照片內容都拿出來,那麼其他的變量和內容,比如寫出文章標題和內容,任何人都可以告訴我我哪裏會出錯?在此先感謝你們。PHP圖像上傳和寫入數據庫
<?php
session_start();
include_once('../php/connection.php');
if (isset($_SESSION['logged_in'])) {
if (isset($_POST['title'], $_POST['content'], $_FILES['photo1'])) {
$title = $_POST['title'];
$content = nl2br($_POST ['content']);
$photo1=($_FILES['photo1']);
$target = "../lifestlye";
$target = $target . basename($_FILES['photo1']);
$query =$pdo->prepare('INSERT INTO article (article_title, article_content, photo_1) VALUES (?,?,?)');
$query->bindValue(1, $title);
$query->bindValue(2, $content);
$query->bindValue(3, $photo1);
$query->execute();
move_uploaded_file($_FILES['photo1'], $target);
{
}
header('Location: index.php');
}
?>
<form action="add.php" method="post" autocomplete="off"/>
<dl class="field four columns centered">
<dd><label for="title">Article Title</label></dd>
<dt class="text"><input type="text" name="title" id="title"/>
</dt>
</dl>
<dl class="field nine columns centered">
<dd><label for="content">Content</label></dd>
<dt class="textarea">
<textarea name="content" id="message"></textarea></dt>
</dl>
<p class="blacktext">Photo</p>
<input type="file" name="photo1">
<input type="submit" id="add article"/>
</form>
可能重複到使用PHP的服務器。將文件名存儲在MYSQL數據庫中,以及其他配置文件信息](http://stackoverflow.com/questions/450876/upload-image-to-server-using-php-store-file-name-in-a-mysql-數據庫與其他) – 2013-05-12 16:05:12
請參閱此:http:// stackoverflow。com/a/16499251/1846562 – mpyw 2013-05-12 16:21:40