Search code examples
phpphpthumb

PHP script giving no such file or directory error


I'm trying to use this php thumbnail generator http://phpthumb.gxdlabs.com/ and i keep getting the error below.

Warning: imagejpeg() [function.imagejpeg]: Unable to open 'Images/uploaded/thumbnails/' for writing: No such file or directory in D:\Data\Websites\wamp\www\StephsSite\PHP\phpThumb\GdThumb.inc.php on line 672

Here's my script

 <?php
        require_once 'PHP/phpThumb/ThumbLib.inc.php';

        $options = array('jpegQuality' => 80, 'preserveAlpha' => true);

        try {
            $thumb = PhpThumbFactory::create('Images/Drew.jpg', $options);
        }
        catch (Exception $e) {
            echo "problems...";
        }

        $thumb->adaptiveResize(200,200)->save('Images/uploaded/thumbnails/');   
?>

and here's some of my file structure testThumb.php/Images/uploaded/thumbnails


Solution

  • Sorry, I have to ask: does the Images/uploaded/thumbnails/ directory exist?

    As a second thought, the error seems to also indicate that it's trying to open the directory for writing. Are you sure that save doesn't need a file name?

    In fact, I think it does. From this page:

    Saving Images: Saving images is pretty easy. You need only pass the full path to where you wish to save the image (including the file name) the the save function.

    So, I would try something like:

    <?php
        require_once 'PHP/phpThumb/ThumbLib.inc.php';
        $options = array('jpegQuality' => 80, 'preserveAlpha' => true);
        try {
            $thumb = PhpThumbFactory::create('Images/Drew.jpg', $options);
        } catch (Exception $e) {
            echo "problems...";
        }
        $thumb->adaptiveResize(200,200)->save('Images/uploaded/thumbnails/Drew.jpg');   
    ?>