Likewise, storing your files in a MySQL database wouldn't be very practical if there wasn't a way to retrieve them. The way we are going to learn to do this is by assigning each file a URL based on their ID number. If you will recall when we uploaded the files we automatically assigned each of the files an ID number.
One of my blog follower Vikash Singh from West Bengal, requested me to provide some codes so that he can upload multiple images create thumbnails and save path to database with php and mysql. I could have directly sent him the codes but I am posting in my blog so that someone with similar problem could benefit from his request. Scope of this script I have posted similar topics before, check,. But in this case there’s a slight catch. When you upload multiple images, a thumbnail will be generated accordingly and its path will be stored in mysql database. So if you upload 4 images then total 8 images are stored. Setup a form to upload multiple images First of all you need to setup your form with file fields so you can attach multiple images.
Here’s the first approach where you can attach multiple images using one file field. Make sure the name ends with and multiple=”multiple” attribute must be present. ? Steps to create thumbnails with PHP Image Magician Why re-invent the tool if you already have them. Is a very nice library to manipulate images. It’s features not only limit to creating thumnails, you can perform many amazing task like add text, resize,crop,sharpen, give color, save to transparent images and many more.
Check the for more details. Moving futher, you have to create a folder name “ uploads” to save the main/larger images and inside uploads folder create “ thumb” folder which will save the thumbnail of that image. The trick is that the thumnail version of the image will have the same name as the main/larger image just seperated by the directory name. Khan, Very nice and detailed working script!
Already learned a great deal about php and PDO sql in this single exercise! I am currently working on a similar project, and I want to know if you can give me some advice on it. Firstly, in my server there will be an “original” folder, and inside that folder, there will be a couple sub-folders called “apple”, “banana”, “orange”, and a folder which is called “combined”.
After users upload an image, their image will first be saved and moved to the “original” folder, if that is successful, I will then apply image magician to it, and save the new modified image into one of the 3 sub-folders, also saving an copy of that into the “combined” folder. So in total there will be 3 copies of image created. The original image in “original” folder, one copy of the image in one of the 3 sub-folders, and one copy in the “combine” folder.
Secondly, the reason for saving 3 copies of the same image is that on my website, there will be 4 tabs, “apple”, “banana”, “orange” and “mainpage”. Inside “apple” link, there will be all pictures exclusively about apple, and same goes to “banana” and “orange”, and in “mainpage”, there will be all the pictures from “apple”, “banana”, “orange”. Finally, there will be 4 tables in my SQL, being “mainpage”,”apple”, “banana”, “orange” and the name of the files will be saved into the tables as well as the created time from the timestamp option, and will then be retrieve from the assigned webpage tabs. My questions are as following: Is my logic correct? How do I display the images according to the created time in time stamp, I am hoping to list it from new to old. Thank you so much again for the code, and any feedback would be very much appreciated!
Best regards, Ray.W. Since you are saving the same copy of image in 3+1 folder it doesnt make sense to save the name of the in multiple tables.
Here’s what you can do. Save the first image in “Original” folder say “abc.jpg” and then use the same name for when you save a copy for other images in other 4 folders. Save the name of the file in the table. Now when you display those images in the tabs just change the folder path for each tabs like for orange “orange/abc.jpg” for apple “apple/abc.jpg”.
Hope this helps you.