ftp_size returns -1 even if it is not a directory
Posted: Wed Sep 16, 2009 3:00 am
Hi guys,
I am using ftp functions to delete files in an ftp server...
i have this code:
Now, my server contains files like this:
/php [directory]
/scripts [directory]
/index.html [file]
/index1.html [file]
/upload.php [file]
If I would open directory '/', ftp_size would return
/php [-1]
/scripts [-1]
and the rest is read as a file which is good.....
the problem is, I want to remove the /php [directory] through
ftp_rmdir but it can't remove the directory because it is empty...
Now, when I go through the directory /php, it has subdirectories and files
within it:
/php/post/ [directory]
/php/put/ [directory]
/php/a.html [file]
/php/b.php [file]
when I do ftp_size through all those files, it would return -1 to ALL, including
/php/a.html
/php/b.php
which should be a file....
So that's my problem....
I tried to change the value of $dir which is '/' to '/php/' but the
result is, it would still return -1 for ALL even though it is not a directory...
that hinders me from deleting the non empty directory because ftp_size would
return a -1 even though it is a file, and not a directory...
What could be the problem???
I am using ftp functions to delete files in an ftp server...
i have this code:
Code: Select all
$conn_id = ftpconnect($user,$password);
$dir = '/';
// Open a known directory, and proceed to read its contents
if($contents=ftp_nlist($conn_id, $dir)){
foreach($contents as $file){
if (ftp_size($conn_id, $file) == -1) {
$link ='/'.$user.'/';
$path = str_replace(' ','%20',$file);
//output as [ directory ]
echo '
<tr id="'.$file.'" onmouseover="mouseover(this.id)" onmouseout="mouseout(this.id)">
<td height="21"><input name="checked[]" type="checkbox" value="'.$file.'"> <img src="icons/folder.png">
<a href='.$link.$path.' class="style2">'.$file.'</a></td>
<td>---</td>
<td>---</td>
</tr>
';
}
}//endforeach
foreach($contents as $file){
if (!(ftp_size($conn_id, $file) == -1)) {
//get the image extension
$img = explode('.',$file);
//get the last modification date and time of the certain file
$size = round(ftp_size($conn_id,$file)/1024)." Kb";//file size in kb
if($size > 1000)
{
$size = round($size/1024)." Mb";//file size in Mb
}
$lastmodified = date("d-M-Y H:i",ftp_mdtm($conn_id,$file));
$link ='/'.$user.'/';
$path = str_replace(' ','%20',$file);
echo '
<tr id="'.$file.'" onmouseover="mouseover(this.id)" onmouseout="mouseout(this.id)">
<td height="21"><input name="checked[]" type="checkbox" value="'.$file.'"> <img src="icons/'.$img[1].'.png">
<a href='.$link.$path.' class="style2">'.$file.'</a></td>
<td>'.$size.'</td>
<td>'.$lastmodified.'</td>
<input name="dir" type="hidden" value="'.$dir.'">
</tr>
';
}//endif
}//endforeach
}
else
{
echo 'Not a directory';
}
?>Now, my server contains files like this:
/php [directory]
/scripts [directory]
/index.html [file]
/index1.html [file]
/upload.php [file]
If I would open directory '/', ftp_size would return
/php [-1]
/scripts [-1]
and the rest is read as a file which is good.....
the problem is, I want to remove the /php [directory] through
ftp_rmdir but it can't remove the directory because it is empty...
Now, when I go through the directory /php, it has subdirectories and files
within it:
/php/post/ [directory]
/php/put/ [directory]
/php/a.html [file]
/php/b.php [file]
when I do ftp_size through all those files, it would return -1 to ALL, including
/php/a.html
/php/b.php
which should be a file....
So that's my problem....
I tried to change the value of $dir which is '/' to '/php/' but the
result is, it would still return -1 for ALL even though it is not a directory...
that hinders me from deleting the non empty directory because ftp_size would
return a -1 even though it is a file, and not a directory...
What could be the problem???