News:

Click here for Toll-Free Service for your business starting at $2.00 per month

Main Menu

Files Won't Delete?

Started by Ben, November 10, 2007, 07:25:49 PM

Previous topic - Next topic

Ben

Okay, with the massive amount of questions we've been getting on this, I figured it might as well be useful to make a topic about this.

Your files won't delete via FTP if they were created via PHP.  Your files also won't delete via PHP if they were created via FTP. To delete php files, you're best bet is to use the function below.

Taking code from the php manual (http://us.php.net/manual/en/function.rmdir.php#78687)
<?php
function RecursiveFolderDelete $folderPath ){
  if ( 
is_dir $folderPath ) ){
    foreach ( 
scandir $folderPath ) as $value ){
      if ( 
$value != "." && $value != ".." ){
        
$value $folderPath "/" $value;
        if ( 
is_dir $value ) ){
          
RecursiveFolderDelete $value );
        }elseif ( 
is_file $value ) ){
          @
unlink $value );
        }
      }
    }
    return 
rmdir $folderPath );
  }else{
    return 
FALSE;
  }

?>


Call this function on any sub-folder on your account, and anything left once this function is done should be able to be deleted via ftp.

If you still have problems after this, feel free to use the contact form and we'll help from there.
--Ben
Ben@freepgs.com

bonehead

Nice, but maybe fix the file permission errors on freepgs side?

Ben

Problem is with security. Say you have a file uploader that isn't validating files properly, and it allows you to upload a .php file. Someone uploads a file similar to that, and manages to delete all files on your entire site.


It's a never-ending battle between security and functionality.
--Ben
Ben@freepgs.com

brainiac744

You could also set PHP to chmod the files to a less restrictive permission setting as you upload files if you wanted. This is hardly a freepgs "permission error"

bonehead

What? if you give someone your password then you deserve it. Else allow account owner all permission rights over files.