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
https://forums.phpfreaks.com/topic/114207-if-not-found-display-not-found-text/
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);
?>

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.