Jump to content

If not found, display "not found" text.


napalm

Recommended Posts

Alright well i got this script that counts how many files are in a users directory you see?

 

But if a user hasn't uploaded yet, lets say if there new then they don't have a folder yet because we have it set up your folder gets created when you upload files.. Theres a big ol' error because it cant find that users directory..

 

the script im using to count files.

<?php			
$gallery = opendir($whichSection . "upload/v2/"  . $member_data['username'] .  "/");
$counter = 0;
while($file = readdir($gallery)){
   if($file != '.' && $file != '..'){
      $counter++;
   }
}
closedir($gallery);
echo($counter);
?>

 

The error it shows

 

Warning: opendir(upload/v2/theusername/) [function.opendir]: failed to open dir: No such file or directory in /home2/battlege/public_html/pivothost/animatorhost/apanel3.php on line 267

Warning: readdir(): supplied argument is not a valid Directory resource in /home2/battlege/public_html/pivothost/animatorhost/apanel3.php on line 269

Warning: closedir(): supplied argument is not a valid Directory resource in /home2/battlege/public_html/pivothost/animatorhost/apanel3.php on line 274
0 / 1500 

 

 

i was wondering if there was away if there is not a a directory created yet or if its "not found" is there a way to display content stating so?

 

im not the best php person ever but i tried

 

	}else{

		echo("Not Found!");

}

 

No work :(

 

 

Well if some one could help it be great! Thanks!

 

NapalM

Link to comment
Share on other sites

<?php
if ( !is_dir( "upload/v2/"  . $member_data['username'] .  "/" ) ) {
die( "Directory Not Found!" );
}
$gallery = opendir($whichSection . "upload/v2/"  . $member_data['username'] .  "/");
$counter = 0;
while($file = readdir($gallery)){
   if($file != '.' && $file != '..'){
      $counter++;
   }
}
closedir($gallery);
echo($counter);
?>

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.