PHP Help...

FOBSIDE

Platinum Member
Mar 16, 2000
2,178
0
0
Okay, I made a quick run through a PHP book I borrowed and it's pretty much useless. It doesn't describe stuff well at all and doesn't break down the examples into understandable parts. I can code in ColdFusion and I'm assuming the process is similar in PHP. The problem is that I can't find any specific help on what I'm trying to do. I see a lot of scripts with more than I'm asking for and I can't read through the "junk" to figure out what I want.

The first thing I am trying to make is an automated thumbnail gallery. I want thumbnails on a page, generated on the fly preferably, and some description text under each thumbnail. I figure since I want descrtiptive text, I have to use a database. I want to do this step by step so I learn it. Please let me know if I should make changes to my approach.

First, I want to assume my information is in the database. Eventually, I would like to have a script upload files and add information to the database but I'd like to get the gallery part working first. I want an index.php in a folder 'FOLDERNAME' which will be the gallery name as well.

1. Grab image name and description where gallery is FOLDERNAME
2. Loop auto-generate thumbnails, adding text, and adding links to images.

Assuming that works, I want to create an image upload page, which will allow me to upload one image at a time to a specified directory/gallery.

1. Upload field
2. Description text field

This will upload the image, and write the following to the database: image name, description text, and gallery (noted by the folder the image was uploaded to). I also want to make sure that any image uploaded belongs to me. I guess that's chown(). I'm not sure how that works exactly. Are the thumbnails that are generated, permanent or are they generated each time to the page? If they're permanent, I guess I would just add them to the database as well and not recreate them every time.

I know I just asked for a lot. Thanks for any help you can give me. :)
 

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
K, so first you need a database. So go get PHP Triad or talk to your Hosting provider bought getting MySQL setup.

Go to www.PHP.net and read about the functions for images. It'll tell ya how to resize images.

Setup your database so records in the table have the following fields:

id, folder, desc, link


From there, make an HTML form which allows you to do the following, enter an Image Description (textarea name="desc"), upload an image, (input type="file" name="file"), and an image link (input type="text" name="link") or something along those lines.

When the form submits, it will create variables with the form input names, so whatever you entered in the image description field, there is now a string with variable name $desc containing waht you entered. Same for the other stuff.


Now, use mysql_connect, mysql_db_select, mysql_query and mysql_insert_id to connect to the MySQL database, insert the information, and get back the ID that was inserted, use PHP to copy the file to the correct directory and name it by the insert ID. Use PHP to resize teh image and name that something else. To get stuff back out, use mysql_query and mysql_fetch_array to get all the information back out of the database, refer to the images by like this: <?php print ("<img src="$mysql_result[folder]/$mysql_result[id]">"); ?>

Use a While loop to fetch all the information from the database, ie:

$temp = mysql_query ($query) or die (mysql_error());
while ($result = mysql_fetch_array ($query)) {
print ("<img src="$mysql_result[folder]/$mysql_result[id]">");
}

etc. etc. etc.

Thats as detailed as I can get for now, feel free to email me at Keithp@LogoSoftwear.com if you need a more detailed explanation. Obvoiusly that all changes if you're using another db...

 

FOBSIDE

Platinum Member
Mar 16, 2000
2,178
0
0
thanks guys. ill take a look at it when i get back to my apartment. i just need simple examples to understand all of this. unfortunately most everything i find is very well done with all these features. i cant separate one thing from the other. we shall see if i can figure this out though... :)
 

FOBSIDE

Platinum Member
Mar 16, 2000
2,178
0
0
ok i got a upload script from one of the php sites. one thing i have a problem with is that when the files are uploaded, they are owned my 'apache' and i cant seem to change this. chown() doesnt seem to be working. i can chmod() it but i cant seem to change the owner. chmod() works for now i guess because it allows me to delete the file if i want later but i think it would be better if i was the owner.

if ($success) {
//this works...chmod($path . $my_uploader->file['name'],0777);
chown($path . $my_uploader->file['name'],MyUserName);
// Successful upload!
print($my_uploader->file['name'] . " was successfully uploaded! <a href=\"" . $_SERVER['PHP_SELF'] . "\">Try Again</a>");
}