|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
inserting images into database
i'am having trouble trying to insert images into database, at the moment year, make, model, price are all being inserted but there is an empty slot showing where i am trying to insert the image.
this is the first time that i've attempted to insert an image so any advice, or good articles is appreciated. want am trying to do is to simple insert an images along with other data and be able to retrieve image relating to this data, without having to download it. Code:-------------------------------------------------------------------------------- $sql = "INSERT INTO joesauto SET year= '$_POST[year]', make='$_POST[make]', model= '$_POST[model]', price= '$_POST[price]', picture_name ='$_POST[picture_name]'"; exec("cp '$_POST[picture]' C:/Web Projects/images/'$_GET[picture_name]'"); |
|
#2
|
|||
|
|||
|
If I can offer a word of advice, it would be to NOT store the actual image in the database, but rather the path to a file on the server.
ie: File Location -> http://www.yoursite.com/images/image_name.jpg" This way you're database won't be filled with BLOB data, which can dramatically increase the size of your database. You're better off storing the path to the file in your image field. Then when you retrieve the values from your DB, retrieve the path, and place that value within an <IMG> tag, and you're off!
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#3
|
|||
|
|||
|
Using Photos with a database
I agree with not inserting photos into a database, its not fun and really does not
serve any purpose unless you want a slow database or you are securing images. I wrote a tutorial on how to use images with a database, heres the url: URL Happy Coding, |
|
#4
|
|||
|
|||
|
We actually already have a article on this subject.
URL |
|
#5
|
|||
|
|||
|
I fully agree with storing files on disc, and not in the db.
That said, I think the uploaded files are accessible through $_FILES not $_POST. Also make sure you for mis of type "enctype = multipart/form-data " |
|
#6
|
|||
|
|||
|
To JoelPhil
Great articles its exactly what i was looking for, much better than storing the actual image in the database. In your article you manually put the images in at the mysql prompt, what i was hoping is that you could explain or give an example of how to put the link in from a form. The reason i ask is that i am under pressure to finish this as part of my final year project and i'am quickly runing out of time. thank you in response |
|
#7
|
|||
|
|||
|
There is a perfect example in the php manual under
Features Handling file uploads. You can probably cut and paste it. Like so: <form enctype="multipart/form-data" action="_URL_" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="1000"> Send this file: <input name="userfile" type="file"> <input type="submit" value="Send File"> </form> <?php // In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES. if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { //Save uploade file to disc copy($_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file"); } else { echo "Possible file upload attack. Filename: " . $_FILES ['userfile']['name']; } /* ...or... */ move_uploaded_file($_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file"); Then to insert into db $pic = $_FILES['picture_name']; $sql = "INSERT INTO joesauto SET year= '$_POST[year]', make='$_POST[make]', model= '$_POST[model]', price= '$_POST[price]', picture_name ='$pic'"; Uploaded file have a set of accessible values $_FILES['userfile']['name'] The original name of the file on the client machine. $_FILES['userfile']['type'] The mime type of the file, if the browser provided this information. An example would be "image/gif". $_FILES['userfile']['size'] The size, in bytes, of the uploaded file. $_FILES['userfile']['tmp_name'] The temporary filename of the file in which the uploaded file was stored on the server. $_FILES['userfile']['error' ?> |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Database Development > inserting images into database |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|