Jump to content

PHP and Directories


jwmstudios

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/22290-php-and-directories/
Share on other sites

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?????
Link to comment
https://forums.phpfreaks.com/topic/22290-php-and-directories/#findComment-99830
Share on other sites

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-php

Creating 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.
Link to comment
https://forums.phpfreaks.com/topic/22290-php-and-directories/#findComment-99850
Share on other sites

[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
Link to comment
https://forums.phpfreaks.com/topic/22290-php-and-directories/#findComment-99852
Share on other sites

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 asking
1) upload file
2) 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 button
echo "<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 listing
closedir($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.
Link to comment
https://forums.phpfreaks.com/topic/22290-php-and-directories/#findComment-100214
Share on other sites

  • 3 years later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.