Current location: Hot Scripts Forums » Programming Languages » PHP » Problem with handle on opendir


Problem with handle on opendir

Reply
  #1 (permalink)  
Old 09-22-03, 04:19 AM
!!BUBBLES!! !!BUBBLES!! is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Problem with handle on opendir

When I open a directory I want to check if a handle has been given... Currently I'm using this:

....
if ($handle = opendir('./testmap/'))
{
echo "Please select data file";
while (false !==($file = readdir($handle)))
{
.....
}
}
else {print "Can't open dir";}

can someone tell me why this doesn't work, cause i'm stuck..
Reply With Quote
  #2 (permalink)  
Old 09-25-03, 05:38 AM
ermau's Avatar
ermau ermau is offline
Wannabe Coder
 
Join Date: Aug 2003
Location: Florida, USA
Posts: 240
Thanks: 0
Thanked 0 Times in 0 Posts
I'm not quite sure what your trying to do with this code.. what do you mean to check if a handle has been given?
__________________
PHP / mySQL Developer
Reply With Quote
  #3 (permalink)  
Old 09-25-03, 05:41 AM
!!BUBBLES!! !!BUBBLES!! is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
If you try and open a dir of file, a handle is returned, except when it isn't possible, then false is returned. Normally you'd expect that
if ($handle).

should work.. but it doesn't

does anyone know why?
Reply With Quote
  #4 (permalink)  
Old 09-25-03, 07:46 AM
Chroder Chroder is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Toronto, Ontario
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Try it like this;

PHP Code:

<?php


$directory 
"/somedir";

if(
is_dir($directory) && ($handle = @opendir($directory)))
{
    
// .......
}

else
{
    die(
'Could not open directory');
}

?>
__________________
DevBox.net | DevBoxForums.com
Reply With Quote
  #5 (permalink)  
Old 09-25-03, 07:48 AM
!!BUBBLES!! !!BUBBLES!! is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
tnx... that works!!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
checkbox.length problem Hawaii 5-0 JavaScript 3 11-27-03 02:15 PM
file download problem ukyankee Perl 6 10-04-03 10:39 PM
session problem afkaar PHP 0 08-27-03 04:43 AM
Include problem lapo4ka18 PHP 3 08-23-03 08:03 PM
jpGraph axis labeling problem Squeezer PHP 2 08-20-03 07:53 AM


All times are GMT -5. The time now is 06:17 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.