PDA

View Full Version : Storing and using images


taffd
07-26-2007, 04:03 PM
I am planning an extension to my website that will be based on a template.
For the sake of argument let's suppose that the page caters for 5,000 clubs. While the general layout and options can all be based on the template, I want to put each clubs logo on their own page. I realise that there are two methods, either store images in a database or in a file and call them from a link in a database. Assuming I am uploading all the images, which would be the simplest solution. I use dreamweaver 8, mysql and php.
I can see that if they were in a database, putting them onto the page would be easy but uploading them would be difficult.
If I used a file based system, uploading would be easy but I don't know how to get them onto the page.
Your thoughts please.

abduraooft
07-26-2007, 04:24 PM
OK, I presume each club have their own id (in DB)

Then, your code may be like

1) Create a directory for each club(To prevent over writing of images with same name)
2)Get the original file name and generate a relative path by appending the directories and the file name (say logos/123/logo_pic.jpg)
3) Save this path for each club, and thus their is no need to search for a logo.
4) Display the logo by just giving this path in the src of img tag

(You must check the type of uploaded file)

Hope this will suit

taffd
07-26-2007, 04:40 PM
Thanks abduraooft,
How about this. The directory for each club, is in fact a field in a database, one of the columns being image_url and containing, as you say the src of image.
This sounds perfect.

taffd
07-26-2007, 08:28 PM
Yahoo. Thanks abduraooft. Everything works as I wanted. For the benefit of anyone else who might be interested here's exactly how I did it.
I created a table in my database,with, at present, 3 fields - clubpageID, clubID and imageurl.
I uploaded into an assets file the relevant images. Names are irrelevant. Because I use dreamweaver it was easy to find the src of the img. I copied this and inserted it in the imageurl field of the database, along with the clubID.
I queried my database filtering with the session variable clubID and I used the following piece of code to place it on the page.
<img src=" <?php echo $row_clublogo['imageurl']; ?> "/>

I can now give x,000 clubs access to their own page, though I've only built one.
Again, Many thanks
Taffd