jwmstudios Posted September 27, 2006 Share Posted September 27, 2006 Hello i am building a photo album using PHP but i would like for the script to automatically detect a folder(directory) and the jpg files (using MIME) inside of it, i would like for the script to automatically create thumbnails and when clicked on they become larger. Could anyone point me in a direction on how i can get this done? Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted September 27, 2006 Share Posted September 27, 2006 your talking about the script looking at a folder getting the jpg's and creating thumbnails on the fly for the whole folder. Not doing this on the upload of the image?????I have a script that will create a thumbnails from a JPG file uploaded. then embed both the original and the thumbnail in a DB with other info and once a search is done the album is displayed using the thumbnail and once the thumbnail is selected a second script is used to pull the photo it self out of the DB. But this is diff then mass creation based on a folder........ and I believe that is what your looking for????? Quote Link to comment Share on other sites More sharing options...
jwmstudios Posted September 27, 2006 Author Share Posted September 27, 2006 I am looking for a script similar to yours, but am not sure how to get the php to detect the jpgs once the files are uploaded, i have an idea of how to resize an image using php, i am currently following this article: http://www.sitepoint.com/article/image-resizing-phpCreating the directory i know can be done with mkdir() i can easily put the pathname in a database and create a type of index and tag it to each photo uploaded. But my problem is php detecting the jpg file and generating the thumbnail. If you can assist me i would really appreciate. Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted September 27, 2006 Share Posted September 27, 2006 [code=php:0] $upload_dir="store/"; //Source File path $thumbnail_path="store/Thumb/"; $ext = substr($form_data_name,strlen($form_data_name)-3); $ext = strtolower($ext); // Verify file extention as supported formats if ($ext == "jpg") { if (move_uploaded_file($form_data,$upload_dir.$form_data_name)) thumb_jpeg($form_data_name,$upload_dir,$thumbnail_path); $datatn = addslashes(fread(fopen($thumbnail_path.$form_data_name, "r"), filesize($thumbnail_path.$form_data_name))); }[/code]oops there is also a filetype function Quote Link to comment Share on other sites More sharing options...
jwmstudios Posted September 27, 2006 Author Share Posted September 27, 2006 not sure if i understand the script ??? But i have an idea of what it is doing. Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted September 28, 2006 Share Posted September 28, 2006 ok lets try this in your htdocs root of your web site create a dir [Store] and under that create [Thumb]here is a basic script that will do what your asking1) upload file2) check file extensions last three char [jpg]3) if jpg move file from temp location to [Store]4) create thumbnail of that file and store in [Store/Thumb]5) get dir list of [Store/Thumb]6) Hyper Link the Thumbnail to the large photo located in [Store] so if some one clicks on the Thumbnail the photo opens up in a target window.[code=php:0]<?if ($submit){ /* Add backslashes before characters that need to be quoted in database queries etc. These characters are single quote ('), double quote ("), backslash (\) and NUL (the NULL byte). */ $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); // Get file extention $upload_dir="store/"; //Source File path $thumbnail_path="store/Thumb/"; //Thumb Nail Storage $ext = substr($form_data_name,strlen($form_data_name)-3); // get last three char of filename $ext = strtolower($ext); // set file ext variable // Verify file extention as supported formats if ($ext == "jpg") { // if jpg ext then move file to create thimbnail if (move_uploaded_file($form_data,$upload_dir.$form_data_name)) // Call Thumbnail function thumb_jpeg($form_data_name,$upload_dir,$thumbnail_path); // Display message Thumbnail was created. echo "<center><h3>".$form_data_name." Thumbnail Created</h3></center>"; }else {// if format is not supported display message echo "<center><h3>".$ext." file format is not supported. Please try again (JPG only)</h3></center>"; }}function thumb_jpeg($image_name,$source_path,$destination_path){//Create Thumbnail $new_width=50; //Image width Change if needed $new_height=50; //Image height Change if needed $destimg=ImageCreate($new_width,$new_height) or die("Problem In Creating image"); $srcimg=ImageCreateFromjpeg($source_path.$image_name) or die("Problem In opening Source Image"); ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die("Problem In resizing"); Imagejpeg($destimg,$destination_path.$image_name) or die("Problem In saving");}// Display input box to upload file with submit buttonecho "<form method='post' action='$PHP_SELF' enctype='multipart/form-data' name='s'>";echo "File to upload/store in database: <input type='file' name='form_data' size='64'>";echo "<br><input type='submit' name='submit' value='submit'>";echo "</form>";// Get list of path $dhr = opendir($thumbnail_path);// While loop if path was returned while (false !== ($file = readdir($dhr))) {// if file found call subroutine and pass path and filename if (!is_dir("$dirpath/$file")) {// if not this filename if ($file <> "Thumbs.db") {// display thumbnail picture echo "<a href ='store/".$file."' TARGET='_BLANK'><img src='store/thumb/".$file."' Width='50' height='50'>"; } }}// Close path listingclosedir($dhr);?>[/code]Everything you need to create your script to list a folder and create thumbnails is a part on this script work with it and you can get what your looking for. Quote Link to comment Share on other sites More sharing options...
jwmstudios Posted April 20, 2010 Author Share Posted April 20, 2010 is there a way to manually upload files (images folder zipped) to a server and direct php script to the path of the server and let it extract the files and resize and thumbnail them? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.