Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,207,528 members, 7,999,347 topics. Date: Monday, 11 November 2024 at 04:18 AM |
Nairaland Forum / Science/Technology / Webmasters / Php Question (1170 Views)
Php Question by worldbest(m): 2:35pm On Mar 28, 2008 |
Hello everyone,am currently working on a site which involves image upload,i was wondering if its ok to save the image url/directory in the database rather than the image itself.Although,i have succeeded in savin the image directory and when referencing from the DB it works pretty well and neat and i also mad a function that deletes the image from the DB and in the image directory whenever the user deletes an image.I need to know the right thing to do.Thanks |
Re: Php Question by my2cents(m): 4:08pm On Mar 28, 2008 |
As with all thingsin life, it depends. What kind of a site is it? Do you have dedicated servers or the regular web hosting accounts? How busy is your site? These are some of the questions you need to ask yourself b4 u make that decision. If you are getting just a few hits per day/month and not dealing with a lot of images, I would say store just the paths to the images, for storage reasons. Otherwise, keep it as is. I hope this helps. |
Re: Php Question by worldbest(m): 4:22pm On Mar 28, 2008 |
Ok thanks alot,so for a social networking site or dating site with gallery and all,which is adviceable to use? |
Re: Php Question by Cactus(m): 4:24pm On Mar 28, 2008 |
I recommend zenphoto, it is light easy simple |
Re: Php Question by worldbest(m): 4:31pm On Mar 28, 2008 |
Ok thanks alot,so for a social networking site or dating site with gallery and all,which is adviceable to use? |
Re: Php Question by my2cents(m): 4:35pm On Mar 28, 2008 |
again, as I stated earlier, it depends on your available bandwidth and DB space. To answer your question as-is, I would say go with storing the actual images in a DB or paying an external host to store them for you and then via your SQL, you access that DB for your photos. |
Re: Php Question by mambenanje(m): 7:29pm On Mar 28, 2008 |
@poster if its not bad dont fix it, so I guess your current solution is working if so move on, and when it starts giving you trouble now you have a reason of fixing it. so if its working and its not costing you much on server and db, then go with it, else look for a better solution |
Re: Php Question by my2cents(m): 7:39pm On Mar 28, 2008 |
I guess Mambe has pretty much said it all. Your question would have made more sense if you hadn't started but since you already have something going, stick with it and hope that you have no reason to refactor OR refactor if you have nothing better to do In the future, try to think out (and ask questions where applicable) various possible solutions to a problem and determine the best solution before implementing. Refactoring definitely costs more in the long-run than if you had actually sat down to come up with the best possible solution upfront. |
Re: Php Question by worldbest(m): 2:03am On Mar 29, 2008 |
Thanks guys.Actually,am currently working locally,what i want to do is a site that allows users 2 upload images for their profiles and their personal galleries,with this i knw i will be dealing with lots of images,so dont u think savin in DB will be sorta difficult when a time comes to move to another hostin company(am nt so sure of what am sayin though)then,just savin in a file can get too populated and cost more right?I have that of saving the path but as my2cent has said its better 2 do something right at this stage 2 avoid probs later. I tryd savin the image in th DB but when i try 2 retrieve i get the path to the image instead.Pls dont ask me 2 go use google,u can help here so other can learn.Thanks again |
Re: Php Question by my2cents(m): 12:03pm On Mar 29, 2008 |
I have never saved images in a DB so I couldn't answer the path part. I do have a question though? How are you saving the image in the DB? Just in case, I think you need to save it as a BLOB. That is the extent to my knowledge with respect to storing images in a DB, since as I said, I haven't done it myself. I hereby yield to others to take it up from here. |
Re: Php Question by Nobody: 1:09pm On Mar 29, 2008 |
to store it in database you need to use blob as 2cents said when outputting, you need to specify the content-type here is a tutorial i got for you from codewalkers.com <?php first, you need to run this sql statement
But from my point of view, i dont think its a good idea to store images in databases i love to be able to move my images around without having to rely on mysql server to interprete the blob for me Again, I might want to update the images using FTP another thing is that it is slower reading images from database what i do is store images in directories and keep the file name in the database(excluding the directory, cos it make it easier to change directory names later on.) |
Re: Php Question by mambenanje(m): 1:27pm On Mar 29, 2008 |
But from my point of view, i don't think its a good idea to store images in databases I support that too. I have used it on my sites (www.ubstudents.com) and its easy to maintain but the problem comes only when you run a very big site with millions of users where you have to do virtual servers and use a grid of computers to power the site, in a case where you think you will need to use grid of computers then I prefer you go with the other option where you encode the picture and store it as blog like in the tutorial. This way if a user uploads his picture in server A and he logins in again and he is being served from serverB his pictures will come from the database which will be one. hey if you don't get this second part then you don't need it. Just follow the first option store name in db and store picture in folder. easy one |
Re: Php Question by worldbest(m): 2:51pm On Mar 29, 2008 |
@webdezzi thanks for the code and to everyone.I have decided 2 stick with just savin the path in the DB cus i think it wil be faster when retrieving.Soon,i'll post my works here. |
Re: Php Question by worldbest(m): 2:57pm On Mar 29, 2008 |
@webdezzi thanks for the code and to everyone.I have decided 2 stick with just savin the path in the DB cus i think it wil be faster when retrieving.Soon,i'll post my works here. |
Re: Php Question by Nobody: 3:07pm On Mar 29, 2008 |
do you have mysql running on a different server from the one hosting your files? |
Re: Php Question by worldbest(m): 5:08pm On Mar 29, 2008 |
No.Am still doing the localhost thingy.No hosting involved yet.Is it possible for a webhosting company to create a folder where all my images will be stored,i have included random numbers to the image names to make them sorta unique.What do u think? |
Re: Php Question by worldbest(m): 5:21pm On Mar 29, 2008 |
No.Am still doing the localhost thingy.No hosting involved yet.Is it possible for a webhosting company to create a folder where all my images will be stored,i have included random numbers to the image names to make them sorta unique.What do u think? |
Re: Php Question by my2cents(m): 10:45pm On Mar 29, 2008 |
I blv u hv to create the folders yourself. As for image names with unique numbers, I want to think that when the user uploads their image, it will be uploaded with the name that they chose (that exists on their end). Since you already have folders which I presume would be named uniquely (maybe the user's username), all you should be concerned with is how to display the images. I hope this helps. |
Re: Php Question by worldbest(m): 9:28am On Mar 30, 2008 |
Yes,the image names are the same with the users name but with random numbers to avoid overwrittin themselves in d case of the gallery. |
Re: Php Question by worldbest(m): 9:56am On Mar 30, 2008 |
Yes,the image names are the same with the users name but with random numbers to avoid overwrittin themselves in d case of the gallery. |
Re: Php Question by Nobody: 11:47am On Mar 30, 2008 |
about creating folders for each user, i will rather have all images in the same folder and have the images in an easy to understand pattern e.g. //the username taken from session $userName=$_SESSION['userSessioN']; //the time $time=time(); $imgName=$userName."_".$time //and if its multiple upload then you can concat some serial numbers to it //with this pattern, you can fish out each user's image based on the prefix something like that sha |
(1) (Reply)
Your Tax Naira At Work. Who Did This Site? / I I Need A Website Designer For A Reality Tv Site: Eg Ambo,peak Etc / What Is Wrong With Liberty Reserve?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 36 |