简体   繁体   中英

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

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');   
?>

I suppose you might want to change the path to Windows style, with backslashes instead of forward slashes. Also, since this file will be written by apache user (thats how it works in *nix, not sure about Windows), you may need to make this directory world writeable and see if that works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM