getimagesize() - No such file or directory

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
neridaj
Forum Commoner
Posts: 40
Joined: Fri Jan 05, 2007 9:55 pm

getimagesize() - No such file or directory

Post by neridaj »

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


I don't understand why I keep getting this no file or directory error when this function is run. function should loop through an array of images and output the width and height but for some reason all I get is warnings about the directory or file being non existent - which from the error output clearly shows the files being scanned by getimagesize().

Here is the error output: "Warning: getimagesize(01.jpg) [function.getimagesize]: failed to open stream: No such file or directory"

Code:

Code: Select all

function get_imgdir()
{
    $propadd = $_GET['pa'];
    $userfolder = $_SESSION['valid_user'];
    $imgdir = 'members/' . $userfolder . '/' . $propadd . '/';
    return $imgdir;
}
 
function get_imgdim()
{
    $dir = get_imgdir();
    $files = scandir($dir);
    foreach($files as $value) {
        // check for image files
        if(valid_image_file($value)) {
            // build image array
            $imgarr[] = $value;
            $count = count($files);
            for($i = 0; $i < $count; $i++) {
                 list($width, $height) = getimagesize($imgarr[$i]);
                 $dimarr[$imgarr[$i]] = array("width" => $width, "height" => $height);
            }
            print_r($dimarr);
        }
    }
}

Is there a better way to go about getting the dimensions of the image?

Thanks,

Jason


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: getimagesize() - No such file or directory

Post by pickle »

You're calling getimagesize() on '01.jpg' - does '01.jpg' exist in the same directory as the script? You're doing a list up of a directory, then passing the filenames along - you need to pass along the full path of the image, not just the name.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
neridaj
Forum Commoner
Posts: 40
Joined: Fri Jan 05, 2007 9:55 pm

Re: getimagesize() - No such file or directory

Post by neridaj »

The directory is retrieved by the get_imgdir function which is where "01.jpg" comes from. The further iterations of get_imgdim reveal all 32.jpg's, which I discarded from the warning output I posted for the sake of brevity.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: getimagesize() - No such file or directory

Post by pickle »

As the error says, getimagesize() is only getting "01.jpg" passed as an argument. get_imgdir() may be getting the directory, but you need to pass that along to getimagesize() so it knows where in the filesystem to look.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
neridaj
Forum Commoner
Posts: 40
Joined: Fri Jan 05, 2007 9:55 pm

Re: getimagesize() - No such file or directory

Post by neridaj »

problem was fixed after concatenating $dir with the arg to getimagesize().

Thanks,

Jason
Post Reply