Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7862897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:18:33+00:00 2026-06-02T23:18:33+00:00

I wanted a script that automatically generates thumbnails when from a folder full of

  • 0

I wanted a script that automatically generates thumbnails when from a folder full of larger images. I’ve ran into some problems implementing it.

I was getting some errors early on because I hadn’t included all the phpthumb files i needed, but now the errors are coming from within the phpthumb code itself. Will post more code as needed.

The errors:

Warning: getimagesize(.\.) [function.getimagesize]: failed to open stream: Permission denied in C:\xampp\htdocs\mysite\GdThumb.inc.php on line 1070

Fatal error: Uncaught exception 'Exception' with message 'File is not a valid image: .\.' in C:\xampp\htdocs\mysite\ThumbBase.inc.php:193 Stack trace: #0 C:\xampp\htdocs\mysite\GdThumb.inc.php(1081): ThumbBase->triggerError('File is not a v...') #1 C:\xampp\htdocs\mysite\GdThumb.inc.php(98): GdThumb->determineFormat()
#2 C:\xampp\htdocs\mysite\ThumbLib.inc.php(127): GdThumb->__construct('.\.', Array, false) #3 C:\xampp\htdocs\mysite\save_differentformat.php(47): PhpThumbFactory::create('.\.') #4 {main} thrown in C:\xampp\htdocs\mysite\ThumbBase.inc.php on line 193

the script:

require_once '../mysite/ThumbLib.inc.php';

$dir = "../mysite/images" ;
$destination = "../mysite/thumbnails" ;
$images = scandir($dir);

foreach ($images as $image)
{
    $ext = pathinfo($dir . DIRECTORY_SEPARATOR . $image,PATHINFO_EXTENSION);
    $thumb = PhpThumbFactory::create($image  . DIRECTORY_SEPARATOR. $image);
    $thumb->adaptiveResize(100, 100);
    $thumb->save($destination . DIRECTORY_SEPARATOR. $image, $ext);
    $thumb->show();
}
?>

EDIT

Here’s the error messages i’m getting right now. It doesn’t know what $mode is and i may have a mix of image types in that folder.

Notice: Undefined variable: mode in C:\xampp\htdocs\mysite\save_differentformat.php on line 51

    Warning: getimagesize(.\.) [function.getimagesize]: failed to open stream: Permission denied in C:\xampp\htdocs\mysite\GdThumb.inc.php on line 1070

    Fatal error: Uncaught exception 'Exception' with message 'File is not a valid image: .\.' in C:\xampp\htdocs\mysite\ThumbBase.inc.php:193 Stack trace: #0 C:\xampp\htdocs\mysite\GdThumb.inc.php(1081): ThumbBase->triggerError('File is not a v...') #1 C:\xampp\htdocs\mysite\GdThumb.inc.php(98): GdThumb->determineFormat()
    #2 C:\xampp\htdocs\mysite\ThumbLib.inc.php(127): GdThumb->__construct('.\.', Array, false) #3 C:\xampp\htdocs\mysite\save_differentformat.php(64): PhpThumbFactory::create('.\.') #4 {main} thrown in C:\xampp\htdocs\mysite\ThumbBase.inc.php on line 193

Here’s what scandir() is returning:

array(19) { [0]=> string(1) "." [1]=> string(2) ".." [2]=> string(36) "13912d3e8b4ae1890457fe935cc0c7fe.png" [3]=> string(36) "266c484ca488d053255c7767af212bee.png" [4]=> string(36) "8af941c37874dc3a7edee2772b60c323.png" [5]=> string(9) "Thumbs.db" [6]=> string(15) "butterflies.png" [7]=> string(22) "butterfliesinverse.png" [8]=> string(11) "favicon.png" [9]=> string(36) "fb9e25f57d12ec5019aa548665f34fa5.png" [10]=> string(20) "image1.png" [11]=> string(25) "image11 (1).png" [12]=> string(21) "image11.png" [13]=> string(25) "image12 (1).png" [14]=> string(21) "image12.png" [15]=> string(21) "image15.png" [16]=> string(20) "image2.png" [17]=> string(21) "image25.png" [18]=> string(21) "image28.png" }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:18:35+00:00Added an answer on June 2, 2026 at 11:18 pm

    OK Apology accepted

    A. It not really advice able to use ../ when dealing with path .. this can lead to a lot of issues my advice is use real path

    B. Always check if the folder exist and you can write to the folder before performing file operations

    Example

    $dir = "mysite/images";
    $destination = "mysite/thumbnails";
    $mode = 0777;
    if (! is_dir ( $dir )) {
        die ( "Source  Direcotry Does not exist :  $dir" );
    }
    
    if (! is_readable ( $dir )) {
        die ( "Source  Direcotry Does not readable :  $dir" );
    }
    
    if (! mkdir_recursive ( $destination, $mode )) {
        die ( "Can't wite  create $destination" );
    }
    
    $images = scandir ( $dir );
    
    $allowedExtention = array (
            "jpg",
            "gif",
            "png" 
    );
    
    $errors = array ();
    foreach ( $images as $image ) {
        $imageFile = $dir . DIRECTORY_SEPARATOR . $image;
    
        if (is_file ( $dir . DIRECTORY_SEPARATOR . $image )) {
    
            if ($image == "." || $image == "..") {
                continue;
            }
    
            $ext = pathinfo ( $dir . DIRECTORY_SEPARATOR . $image, PATHINFO_EXTENSION );
            if (! in_array ( $ext, $allowedExtention )) {
                continue;
            } else {
                $errors [] = $imageFile . " has invalid extention $ext";
            }
    
            try {
                $thumb = PhpThumbFactory::create ( $dir . DIRECTORY_SEPARATOR . $image );
                $thumb->adaptiveResize ( 100, 100 );
                $thumb->save ( $destination . DIRECTORY_SEPARATOR . $image, $ext );
                $thumb->show ();
            } catch ( Exception $e ) {
                $errors [] = "PhpThumbFactory  : " . $e->getMessage ();
            }
        } else {
            $errors [] = $imageFile . " not a valid File";
        }
    }
    
    // Check for errors
    
    if (count ( $errors )) {
        foreach ( $errors as $error ) {
            echo $error . " <br />";
        }
    }
    
    function mkdir_recursive($pathname, $mode) {
        is_dir ( dirname ( $pathname ) ) || mkdir_recursive ( dirname ( $pathname ), $mode );
        return is_dir ( $pathname ) || mkdir ( $pathname, $mode );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a DML script that updates a column but I wanted
I wanted to run my application on iPhone simulator via some script. Is it
I wanted to write a small script that searched for an exact file name,
I wrote an fsi script that worked great and wanted to compile it so
I´m totally new to Powershell and wanted to write a script that deletes all
I have a script that runs to upload an image, then resize it into
I was trying to create a quick little script that would insert data into
I've been working on simplifying a script, I wanted to create a script that
I have a bash script that monitors the jobs in a cluster from the
I was working on a little script that would do some logging for me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.