2012-04-15 51 views
-2

我想將所有的表單值添加到我的數據庫,我知道如何插入新的記錄,但與我想上傳的「圖像」,我堅持。PHP MySQL表格值到數據庫

從數值中插入所有值並上載圖像並將圖像url插入數據庫中的最簡單方法是什麼?

表來源:

<form action="_eventcreate.php" id="contactform" method="POST"> 
<p> 
<label for="event_name">Event Name:</label> 
<input type="text" name="event_name" class="input" value=""> 
</p><p> 
<label for="event_description">Description:</label> 
<input type="text" name="event_description" cols="88" rows="6" class="input" value=""> 
</p><p> 
<label for="event_date">Event Date:</label> 
<input type="text" name="event_date" class="input" value=""> 
</p><p> 
<label for="event_time">Event Time:</label> 
<input type="text" name="event_time" class="input" value=""> 
</p><p> 
<label for="event_cost">Event Cost:</label> 
<input type="text" name="event_cost" class="input" value=""> 
</p><p> 
<label for="event_image">Upload Image:</label> 
<input type="file" name="fileField" id="fileField" /> 
</p> 
<input type="submit" name="submit" value="Create Event" class="submit">      
</form> 

謝謝!

+0

[?你嘗試過什麼(http://mattgemmell.com/2008/12/08/what-you-you-tried /) – PeeHaa 2012-04-15 10:58:18

回答

2

1)使用<input type="file" name="image"/>的 「圖像」 字段上傳。

2)在窗體標籤添加:enctype="multipart/form-data"

3)使用$_FILES集合以獲取有關上傳的文件(S)的信息。

4)使用is_uploaded_file(),move_uploaded_file()檢查文件&將其移動到其最終目的地。

5)確保將文件保存在可通過網絡訪問的目錄中&創建一個URL,以便將其保存在數據庫中。

退房:http://www.php.net/manual/en/features.file-upload.post-method.php

+1

+1不使用w3schools – PeeHaa 2012-04-15 11:02:44

+1

+1000不使用W3SCHOOLS,不在日期:-) – Boldie 2012-04-15 11:40:45

+0

///////////// ////////////////////////// Upload File to Directory \t \t $ uploaddir ='../gallery/'; \t \t $ uploadfile = $ uploaddir。基名($ _ FILES [ 'userfile的'] [ '名稱']); move_uploaded_file($ _ FILES ['userfile'] ['tmp_name'],$ uploadfile); \t \t $ event_image = $ _ FILES ['userfile'] ['name']; – Boldie 2012-04-15 13:06:06

0

CHK這個網址

http://www.w3schools.com/php/php_file_upload.asp 

,你會得到關於如何做一個更好的主意..

,並且可以將你的代碼與圖像的名稱和它的其他插入所有形式的數據cheking是$ _FILES沒有錯誤後的細節...

雖然有很多庫和框架,管理內部,你只需要調用一個函數或2 ... 像

http://pear.php.net/HTTP_Upload 
0

此鏈接可能是有用的:
PHP File Upload
使用$ _FILES [ 「文件」] [ 「名稱」]插入你的數據庫表

0

,甚至更好,你可以嘗試在網上喜歡安定,文件上傳的幅度可用jQuery的文件上傳