Jump to content

[SOLVED] Readdir() problems


bassguru

Recommended Posts

Hello everyone,

 

I have some code that reads from a specified directory and puts the files into an array. The problem is that if there are no files in the directory, then the array is undefined and error messages start appearing all over my site.

 

//Retrieve files that are of a type matching those specified
while($imgfile = readdir($dimg)) {
if(in_array(strtolower(substr($imgfile,-3)),$fileTypes)) {
	$userImage[] = $imgfile;
     		sort($userImage);
    		reset ($userImage);
}
}

 

The 'undefined' array would be $userImage. How do I solve this problem?

 

Many thanks in advance

bassguru

Link to comment
https://forums.phpfreaks.com/topic/173988-solved-readdir-problems/
Share on other sites

I already have validation for that.

 

The directories are unique to each user of the site. They are there to save the user's uploaded images.

 

When users first create an account, there are no images (thus no files) in the directory. Also, the user can delete the image files in the directory at anytime, so I really need something that will solve the problem of an undefined array variable.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.