Database Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesDatabase Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 30th, 2003, 11:32 AM
pjp pjp is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 10 pjp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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]'");

Reply With Quote
  #2  
Old March 30th, 2003, 02:13 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
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

Reply With Quote
  #3  
Old March 30th, 2003, 05:49 PM
JoelPhil JoelPhil is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: California
Posts: 3 JoelPhil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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,

Reply With Quote
  #4  
Old March 30th, 2003, 09:50 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
We actually already have a article on this subject.

URL

Reply With Quote
  #5  
Old March 31st, 2003, 08:26 PM
rickwright rickwright is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Nova Scotia
Posts: 27 rickwright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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 "

Reply With Quote
  #6  
Old April 1st, 2003, 05:14 PM
pjp pjp is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 10 pjp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #7  
Old April 1st, 2003, 07:04 PM
rickwright rickwright is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Nova Scotia
Posts: 27 rickwright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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'

?>

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesDatabase Development > inserting images into database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek