Forum Moderators: coopster

Message Too Old, No Replies

Ftp delete a Symlink?

         

Birdman

7:23 pm on Jul 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does anyone know how to delete a symlink with PHP's FTP functions?

I'm using a recursive ftp_rmdir function but it won't delete the symbolic link.

Thanks in advance!

Habtom

5:06 am on Jul 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Birdman, got the solution?

Birdman

2:05 pm on Jul 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

Yes, I finally figured it out. This function below uses ftp_size() to determine if it's a directory or a file. "-1" usually means it's a directory, except if it encounters a symlink. That also returns -1.

My solution was a hack because I knew the symlink was always going to be a zip file, so I just strpos()ed for ".zip" then used ftp_delete() and it worked.

I couldn't find a ftp function to check for symlbolic links, but I know there is is_link(), which you would then have to determine the server path to the file, not the ftp path.


function ftp_rmAll($conn_id,$dst_dir){
$ar_files = ftp_nlist($conn_id, $dst_dir);
if (is_array($ar_files)){ // makes sure there are files
for ($i=0;$i<sizeof($ar_files);$i++){ // for each file
$st_file = $ar_files[$i];
if($st_file == '.' ¦¦ $st_file == '..') continue;
$size = ftp_size($conn_id, $dst_dir.'/'.$st_file);
if ($size == -1 && strpos($st_file, '.zip') === false){ // check if it is a directory or zip file(sym)

$this->ftp_rmAll($conn_id, $dst_dir.'/'.$st_file); // if so, use recursion
} else {
ftp_delete($conn_id, $dst_dir.'/'.$st_file);
}
}
}
$flag = ftp_rmdir($conn_id, $dst_dir);
//return $flag;
}