2013-04-06 90 views
-5

我想創建一個表單,允許用戶上傳他們的照片,姓名和電子郵件,然後將其保存在數據庫中?
我已經試過這到目前爲止http://www.reconn.us/file_uploading.html上傳圖片和信息

+0

你與你所提供的鏈接解決遇到什麼問題? – 2013-04-06 21:46:47

+0

你試過了,但沒有奏效?請更具體一些。在目前的形式下,你的問題不符合這裏所要求的格式。閱讀[faq]。另外,嘗試在StackOverflow上搜索,您可能會發現相關的問題 – thaJeztah 2013-04-06 21:47:24

+0

請在您的問題中包含所有信息。依賴於一些將要改變/消失的外部鏈接的問題是不可接受的。 – meagar 2013-04-06 21:47:43

回答

1

獲取的圖像作爲你的鏈接解釋,然後讀取臨時文件,並將其存儲在BLOB型領域在數據庫中。完整的示例請參閱here


// Make sure the user actually 
// selected and uploaded a file 
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

// Temporary file name stored on the server 
$tmpName = $_FILES['image']['tmp_name']; 

// Read the file 
$fp = fopen($tmpName, 'r'); 
$data = fread($fp, filesize($tmpName)); 
$data = addslashes($data); 
fclose($fp); 


// Create the query and insert 
// into our database. 
$query = "INSERT INTO tbl_images "; 
$query .= "(image) VALUES ('$data')"; 
$results = mysql_query($query, $link); 

// Print results 
print "Thank you, your file has been uploaded."; 

} 
else { 
print "No image selected/uploaded"; 
} 

// Close our MySQL Link 
mysql_close($link); 
?>