Current location: Hot Scripts Forums » Programming Languages » PHP » Checking if a folder exists


Checking if a folder exists

Reply
  #1 (permalink)  
Old 11-04-11, 08:52 PM
ghego1 ghego1 is offline
New Member
 
Join Date: Nov 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Checking if a folder exists

I know this has been explained many times, but there's something I must be missing, because I still don't get why the following code is not working, anyone can help?!?

Code:
<?php
$foldername = 'http://www.whatsoever.exp/folderIdliketocheck';

if (ffile_exists($foldername)) {
    echo "It exists!!!";
} else {
    echo "No, it doesn't...";
}
?>
Reply With Quote
  #2 (permalink)  
Old 11-05-11, 05:48 AM
scriptdom64 scriptdom64 is offline
New Member
 
Join Date: Jan 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
You should replace ffile_exists with file_exists, only one (f), but the following code may work better for determining if a file is a directory (folder).

PHP Code:

<?php

$foldername 
'http://www.whatsoever.exp/folderIdliketocheck';

if (@
is_dir($foldername))
{
echo 
"Directory exists";
}
else
{
echo 
"Directory does not exist";
}

// not tested
?>

Last edited by UnrealEd; 11-05-11 at 06:38 AM. Reason: added [php] wrapper
Reply With Quote
  #3 (permalink)  
Old 11-06-11, 08:13 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
It won't work with URLs. It only works for local files. If you want to check if a remote folder exists, you could use get_headers() and fetch the HTTP status code.
Reply With Quote
  #4 (permalink)  
Old 11-21-11, 11:40 AM
DLJ DLJ is offline
Newbie Coder
 
Join Date: Nov 2011
Location: 303 See Other
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Another thing you could do is check to see if a file exists in the directory, maybe "check.check" (it doesn't really need to be a file with any contents, just a file existing there for the namesake), and run through "(file_exists('check.check'))". It's a little back-route, but if the file exists, the directory has to exist.
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
[SOLVED] Checking mysql table to see if string exists trumnation PHP 14 07-02-08 06:27 PM
Help - SQL syntax curious Database 2 01-05-07 05:13 PM
Checking a file exists lee PHP 3 04-23-06 12:44 AM
Checking if something exists. DetroitGuy PHP 6 07-10-05 05:32 PM
checking if a value exists endusto PHP 2 03-28-05 06:11 PM


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