Click to See Complete Forum and Search --> : filetype


xavikevicious
December 20th, 2004, 04:40 AM
i have one file and one directory in a folder. i created them with mkdir function and they have 777 permissions. i want to remove both, but i can't to do it because my server no recognize them as a file and a dir.

My code:

$dir=chdir("scripts");

$handle=opendir('./Analisi_Programa_Anticopia/Fitxer');
while ($file = readdir($handle)){
echo "$file\n";
if($fit = is_file($file)){
echo "File? ".$fit."\n";
if(!unlink($file)){
echo "File not remove";
}
else echo "File remove";
}
else if($direc = is_dir($file)){
echo "Directory? ".$direc."\n";
if(!rmdir($file)){
echo "Directory not remove";
}
else echo "Directory remove";
}
else echo "Not file or directory";
$a = filetype($file);
echo "My type file is: ".$a."\n";
}
closedir($handle);

When my file is file type, this not entry in first if and when this is directory, this not entry to the second if. Both write to screen:Not file or directory. On filetype function both files are type files empty. What happens??

xavikevicious
December 20th, 2004, 10:05 AM
easier than last mail that it were longer than this,

i have 2 files in /dir1:

file.zip
directory

With is_file(file.zip) and is_dir(directory), both results false. Why? i am in correct directory: /dir1 because i print its files on screen.

xavik

blueday54555
December 21st, 2004, 08:35 AM
PHP is like c/c++

there is a BIG difference between

if ( $a = $b) //this will be always true !

and

if($a == $b)

visualAd
December 21st, 2004, 09:03 AM
You need to pass the full relative or absolut path to the is_file and is_dir functions. $file is only the name of the file and directory inside the currently opened directory, therefore, if you use is_dir($file) it will look for a directory named $file in the current directory and not the one you've just opened.

visualAd
December 21st, 2004, 09:05 AM
PHP is like c/c++

there is a BIG difference between

if ( $a = $b) //this will be always true !

and

if($a == $b) He wants the assingment operator inside the if statement, in PHP the assignment will be made and the value of the left most expression will be tested. Hence:

if ($var = 1) // will be true

and

if ($var = 0) // will be false

blueday54555
December 21st, 2004, 09:15 AM
yep you are right I didn't saw that !
I saw an If statement and only one "=",
the biggest mistake beginners make :)