php upload image path to database and rename

I have the following code which will resize an image into full size, thumb and mid and place them in files on the server. The form before the user clicks upload ask the user to select a category where the image will go into. Those options are pulled from the database.

How would i make it so that the path of the full size image and the thumb are entered into the database in the image table so that in the gallery i can call them and display them, I don't want to fill up the database with the actual images.

Also, is there a way to have it rename the images like image01.jpg, image02.jpg so that it will check to see what the last 2 digits are and count up so i can keep adding images?

I don't think you need to save the path name in the database if you can organize your files correctly and you have the category name in the database.

You could have an /images directory and below that have subdirectories called full, thumb and mid.

In each of these subdirectories you could have subdirectories for each category.

so, if you have a "family" category your paths would be defined as

/images/full/family

/images/mid/family

/images/thumb/family

You wouldn't be storing anything except for the category name which you probably already have defined somewhere.

For image names I'd be inclined to go with a image_1.jpg image_2.jpg....image_1324.jpg, etc. You can implode / explode the file name using the "_" and you aren't limited to only 100 images per category.

Don't have specific code to do this for you but it shouldn't be too difficult.

Thanks, that worked great for the needing 01, 02 part! Do you know where i'd need to enter my sql statement to get the file path to upload to the server along with the category id, i've tried a few things based on some code i found but nothing adds to the database, the images upload and resize fine though.

CatID will probably be a medium_int type or similar... then it only allows numbers.

You can do 2 things:

a) alter this table and change the type to varchar(255) and store the category directly in the images table

b) Store the category ID in the images table, use: $sql = "INSERT INTO ImageProject2 (ImageLocation, CatID) VALUES ('".$newFileName."', '".$_POST["CatID"]."')";
and then when getting the results of the images query, use also (assuming the categories table is called "categories"): LEFT JOIN categories ON categories.CatID=ImageProject2 .CatID

Featured Post

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…