Page 1 of 1

readdir followed by is_file

Posted: Sun Jul 18, 2010 6:37 pm
by db579
I'm trying to make use of some code for a simple photo gallery but I'm running into problems because the photos are no longer all stored in the same directory as the function script.
The script seems to run into problems at line 42 as the script is no longer stored in the same directory as the images. Full script is attached but this is the section I think I'm having problems with. Thanks very much for any help.

Code: Select all

function generateThumbnails(){
	global $thmb_width,$thmb_height,$dir;

	// Open the album directory
	if ($handle = opendir($dir)) {
		// Read all files from the album directory
		while (! == ($file = readdir($handle)))  {
			// Check whether the item is a valid file
			if (is_file($file)){
				// Check whether the image is a thumbnail
	      		if (strpos($file,'_th.jpg')){
	      			$isThumb = true;
	      		} else {
		      		$isThumb = false;
		      	}

Re: readdir followed by is_file

Posted: Sun Jul 18, 2010 6:50 pm
by Gargoyle
you should really properly format your code if you are asking for help. also, mentioning "line 42" is rather pointless here.

other than that, you just need to supply the directory path by adding

Code: Select all

$file = $dir.$file;

Re: readdir followed by is_file

Posted: Sun Jul 18, 2010 7:20 pm
by db579
Hi thanks for the help and sorry about the formatting. I've tried adding that into the while loop like so:

Code: Select all


while (! == ($file = readdir($handle))) {
$file =$dir.$file;
// Check whether the item is a valid file
if (is_file($file)){

But it still doesn't work. This part does work if I add $dir.$file into the is_file statement itself instead though which is why I'm very confused by this but doing it that way is causing me problems further on. What am I doing wrong? Thanks again

Re: readdir followed by is_file

Posted: Sun Jul 18, 2010 7:24 pm
by Gargoyle
if you want to address a file that is not located in the same folder than the php script executed, you need to specify the folder as well. if this causes you further troubles, you need to revise your code.