Forum Moderators: coopster

Message Too Old, No Replies

Quick and simple Directory exists question

check directory exisits

         

havoc

3:48 am on Apr 28, 2004 (gmt 0)

10+ Year Member



Just wondering, in this script i am writing i need to know if a directory exists and if it does not create the directory.

i have it creating the directory but it will not check to see if the dir exists

say if i had a directory /home/cheese/
how would i script it to check is cheese exisited.

thanks guys

DrDoc

4:54 am on Apr 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if(!is_dir("/home/cheese")) {
mkdir("/home/cheese");
}

is_dir checks if the parameter exists and is a directory...

havoc

5:43 am on Apr 28, 2004 (gmt 0)

10+ Year Member



If need it to check if a varible file or directory exists
for the file i am using

$todir$entry is the file path to the file i want to check

$checkfile = "$todir$entry";
if (!is_file($checkfile))
{
<copy file over>
}
else
{
<file exists go away>
}

This is not successful it allows the transfer to go thru every time :(

Warboss Alex

2:52 pm on Apr 28, 2004 (gmt 0)

10+ Year Member



Is the file you're checking being uploaded by web users? If so, what you want is something like this ..

if (!file_exists($path.$_FILES['file']['name'))
move_uploaded_file($_FILES['file']['tmp_name'], $path.$_FILES['file']['name']);

Where $path is the path to your directory. This checks if an uploaded file isn't already in a directory defined by $path. If so, it copies the uploaded file there. Otherwise, it doesn't do anything, leaving the file already there intact.

Is that what you wanted? Or is it not uploaded files you're working with?

DrDoc

11:30 pm on Apr 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried echoing the variable $checkfile to make sure you don't have any other junk in there, and to make sure the file truly exists?

webadept

2:57 am on Apr 29, 2004 (gmt 0)

10+ Year Member



Along the same lines as DrDoc, did you clear the contents of your variable before you started using it? just to make sure that the last file you looked for isn't still there?