PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 5th, 2012, 10:04 PM
BitZoid's Avatar
BitZoid BitZoid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 98 BitZoid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 20 m 38 sec
Reputation Power: 1
Unhappy PHP-General - Handling images using PHP With MySQL

Hi,

I'm nervous about completing my clients web-application, a mysql database and administrative user interface to manage that database - where all changes would be directly apparent on the public web-site; because I have no idea how to handle images in mysql and php, you can see why I'm nervous.

I've done some research and I think I should store the images on the web server, and put the link to them in the database within its respective row.

However, I have no idea how to generate the proper file names, paths, and the user "Browse for files on computed" upload function.

Does anybody have any pointers to get me started - I'm fairly novice in the implementation of the php and mysql code, maybe intermediate in my understanding of computers and programming.

Reply With Quote
  #2  
Old November 5th, 2012, 11:17 PM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,791 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 14 h 53 m 20 sec
Reputation Power: 6112
1) Uploading files in an HTML form. Use <input type="file"> and you're done.

2) Accepting file uploads in php. See the manual for move_uploaded_file. Make sure the destination is still inside the web root somewhere

3) Naming the destination file. See the manual for uniqid

4) Inserting the file row into the database. You already know this for the rest of your operations, a file path is no different than any other string.

5) Showing the images back to end-users. Print the <img /> tag like any other image, just use the filename in the database. As long as you put it in a web-accessible directory in #2 you should be fine.
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
  #3  
Old November 5th, 2012, 11:23 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)E-Oreo User rank is General 90th Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 43 m 47 sec
Reputation Power: 6991
From a security standpoint, the most critical element is validating the extension of the uploaded file. The manual page on move_uploaded_file should discuss this.
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #4  
Old November 6th, 2012, 04:46 PM
schworak schworak is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 11 schworak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 43 m 11 sec
Reputation Power: 0
This isn't a solution but let me give you a little advice...

If you are talking about a few hundred images, it might be ok to store them in the database. But more than that and you are creating a bottleneck in the system.

Keeping track of image names in the database but keeping the files on the hard drive is more efficient. I say this from experience on several projects where image storage was in the database at first for ease of access. Over time, getting the images required more and more resources and a lot of database traffic.

In every case, we ended up moving all images off the database and into the file system.

Some times we check for the existence of the image every time it is asked for other times only once in a while just in case someone manually deleted it. In most cases we have a Javascript function that fires off when an image can't load to notify our app to go check it and at the same time put up a "no image" image for the user.

If you really need to store the images in the database then so be it. I would just give that some serious thought.

Reply With Quote
  #5  
Old November 6th, 2012, 05:27 PM
notflip's Avatar
notflip notflip is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 148 notflip User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 39 m 9 sec
Reputation Power: 1
A head start

PHP Code:
 $images mysql_query("SELECT img_href FROM images");

while(
$row mysql_fetch_array($images)){
echo 
'<img src="' $row['img_href'] . '" />';



Goodluck!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Handling images using PHP With MySQL

Developer Shed Advertisers and Affiliates



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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap