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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.