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:
Laplink Gold 2008 - $15 Off with Coupon Code CJM9NE
  #1  
Old March 30th, 2003, 10: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, 01: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: 7
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, 04: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, 08: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, 07: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, 04: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, 06: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!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway