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:

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

    getimagesize is looking for the files in the current working directory. Either supply a valid relative path or absolute path to the images.

    i.e.

    list($width, $height) = getimagesize(get_imgdir().$imgarr[$i]);

    edit

    You should not be using $GET without sanitizing the data first. Someone can easily manipulate $GET['pa'] and do some bad things.

      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.

        That's all fine and dandy, but getimagesize still needs the path and the file name, unless the file is in the current working directory, or you change the current working directory before you call getimagesize.

        edit

        Your error even says so: Warning: getimagesize(01.jpg) [function.getimagesize]: failed to open stream: No such file or directory

        edit again

        Maybe this is more clear: Warning: getimagesize(./01.jpg) [function.getimagesize]: failed to open stream: No such file or directory

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

          Thanks,

          Jason

            Write a Reply...