2011-06-23 67 views
-1

好吧,上傳和刪除圖像php sql

我建立了一個插入圖像頁面(uploader.php),但我有2個問題。

的代碼是:

<?php 

$target = "images/test/"; 
$target = $target . basename($_FILES['photo']['name']); 

$title=$_POST['title']; 
$desc=$_POST['desc']; 
$pic=($_FILES['photo']['name']); 

mysql_connect("dbhost", "dbuser", "dbpass") or die(mysql_error()) ; 
mysql_select_db("dbname") or die(mysql_error()) ; 
mysql_query("INSERT INTO `test` VALUES ('$title', '$desc', '$pic')") ; 

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
{ 

echo "The file ". basename($_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
} 
else { 
echo "Sorry, there was a problem uploading your file."; 
} 
?> 

<form enctype="multipart/form-data" action="uploader.php" method="POST"> 
Title: <input type="text" name="title"><br> 
Description: <input type="text" name = "desc"><br> 
Photo: <input type="file" name="photo"><br> 
<input type="submit" value="Add"> 
</form> 

所以第一個問題是,信息不被輸入到數據庫 - 表中有4個領域 - ID(INT),標題(VARCHAR),遞減(VARCHAR )和照片(varchar)。是否因爲id字段沒有被指定?這只是表格的自動遞增主鍵。

第二個問題是,正在加載的圖像中包含空格 - 例如,上傳「test image.jpg」時 - 我想合併一個str_replace來創建「testimage.jpg」。你知道我將它插入代碼的位置嗎?再次

感謝您的幫助,

JD

回答