Forum Moderators: coopster

Message Too Old, No Replies

php and images

help-a-n00b

         

nfs2

9:21 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



Im pretty ok with php and mysql, but one thing ive never done before is make a picture gallery. I know i want to store the image in a directory, and store the file information in a mysql database.

I have a few questions though, for on i dont even know where to start. How to i associate a file in a directory with information on a database?

Second, i'll need to create thumbnails for index views. How do i do that?

I mean im a total n00b when it comes to using images with php. I tried to search for tutorials, but man there is some real crap out there that answer none of my questions.

If anyone can help me id really appreciate it. Ive been at this for hours and gotten nowhere.

nfs2

9:25 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



I should mention that my host has GD and Image majic. I dont know if thats relevent..

inveni0

9:30 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



To generate an ease of use for my current client, I created an image gallery that uses Javascript to page through images. The image URL's are stored in the database. For example:

1) The user submits a "New Image" form, where the only fields filled out are something like Image Title and Image Description.

2) Behind the scenes, a numerical ID is generated (can be autogenerated, or the user can assign a number via the form). From this ID (which is also the Primary Key), three new variables are created, each storing a file name: <?php $Photo1 = $ID."1.jpg";?>

3) This value is then inserted into the database along with the information the user has placed in the form.

4) Upon successful insertion, the user is brought to an upload form, where they choose which image to upload via radiobutton. The value of the radiobutton is pulled from the database using the ID as a filter. For instance, the first photo would be valued <?php echo $row_DataBase['Photo1']?> (Or whatever...I use Dreamweaver, so syntax isn't something I pay much attention to.)

5) This form then allows the user to upload these files however they wish, and uses GD to adjust the size of the images on the fly.

Play with it a bit. For my skill level, this was the easiest way to allow my client the ability to easily add photos to records. Instead of storing the photo...it stores the URL.
It's the simplest

nfs2

9:35 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



When you say it doesnt store the photo, it only stores the url, does this mean that it only links to pictures offsite? Cause i would need the images hosted on my server..

I dont know if i wanna use javasript though.. Im sure theres a simple way of doing it with just php..

nfs2

9:40 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



I also dont get what you mean when you say they upload via a radio button? If i have a picture on my computer that i want to upload, how does the radio button select it? I dont get it

inveni0

9:40 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



By URL, I mean "photo1.jpg". It would be stored on your folder...you'd just enter the link to it like you would in an <img src=> tag.

The radio button gives the variable on how to name the uploaded file. This way the user doesn't have to worry about it. The database stores the name of the file, and the upload form renames, resizes and uploads it.

[edited by: coopster at 9:44 pm (utc) on Jan. 5, 2006]
[edit reason] removed url per TOS [webmasterworld.com] [/edit]

inveni0

10:00 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



My example URL was edited out...so let me try this a bit better:

Let's say your database row contains 4 fields:

1) ID <-primary key
2) Title <-Photo Title (ex. "Crazy Pic")
3) Desc <-Photo Description (ex. "Here I am, being Crazy!")
4) Photo1 <-Photo Filename (ex. "[IDnumberhere]1.jpg")

Fields 1, 2 and 3 would be submitted by the user via a form. Field 4 would be assigned in the next page. Since there's only one photo per entry, you don't need radio buttons, so ignore I said that. You'd just have a file upload script that will name the file to the value stored in Photo1 for that row.

Now, you can plug these values into your template.

nfs2

10:41 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



Ah i get it now, that solves the problem of associating the database info with the actual pic.

Now i just need to figure ou how to create a thumbnail version of the image

inveni0

10:44 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



If you have GD installed, you can use it to create the thumbnail immediately after the user uploads the image. I was just having this problem earlier today, but with simply resizing the image so that the user wouldn't have to learn Paint or Photoshop or anything like that.

I used something from hotscripts that did the trick with a little modification.

nfs2

11:01 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



I wanna keep the origional image. So that on the index will be 3 rows of 4 thumbs or something, then the user can click on a thumb to see the full size pic.

inveni0

11:56 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



Yes, GD can resize the image and save it to a different filename.

topsites

5:42 am on Jan 6, 2006 (gmt 0)



I use pickle, no gd, no bs. Just upload and be done with it (both the script AND the images).

[picklegallery.sourceforge.net...]

Here is a demo:
[picklegallery.sourceforge.net...]

It indexes as much as you want, thumbs and if clicked gives full-size, categorizes and indexes everything, all you have to do is upload the files, literally. I think you need to tell it the directory on the server where the images are located, everything else is automatic.
I have more than a few thousand images indexed thusly, over 200 categories, it even creates subs for you. If you want it to look fancy, get a nice background and configure the header file.

Now if you want your site's VISITORS to be able to play with the file-system, that's another story.

nfs2

10:36 am on Jan 6, 2006 (gmt 0)

10+ Year Member



Im looking at it now, at first it seemed perfect, but the closer i look at it it seems to be made as a plugin for nuke sites. That sucks cause i made my site myself so i dont think it'll work

Thanks anyways

nfs2

10:40 am on Jan 6, 2006 (gmt 0)

10+ Year Member



//edit

sorry, there were 2 versions and i downloaded the nuke version by accedent.. doh! lol