Welcome Guest, Not a member yet? Register   Sign In
Deleting folders and their content.
#1

Hi,

I'm having problems when it comes to deleting specific folders. All folders get deleted inside an "uploads" folder when I only want a single folder deleted.

My application allows new companies to register on the system. When a company registers a new folder gets created inside the uploads folder specific to that company (a random md5 string is used).

My folder setup:

- public_html / htdocs
   - uploads
       - 731e315adc887be41cc84be0f5c73f76
           - avatars
       - b8218d22eaaca5deb91c741c4d7112dd
       - 71913f59e458e026d6609cdb5a7cc53d
       - etc...

In the app I provide admins the ability to delete companies. When a company is being deleted I want all files & subfolders inside the company specific folder deleted and then the folder itself.

The md5 string is stored in a MySQL database (as 'uploads_folder') along with other info about the company.

In the delete function in the Companies class I get the company info using the following:
PHP Code:
$company_folder $this->company_lib->get_uploads_folder($id); 

The get_uploads_folder function inside the Company_lib library simply returns the full path:

PHP Code:
public function get_uploads_folder($company_id)
{
 
   $company $this->CI->company_model->fields('uploads_folder')->get($company_id);

 
   return FCPATH 'uploads'DIRECTORY_SEPARATOR $company['uploads_folder'];


I then load the file helper and call the delete_files function:
PHP Code:
$this->load->helper('file');

// delete all uploaded files for the company
delete_files($company_folderTRUE); 

When the delete_files function runs it deletes all folders inside the uploads folder instead of just deleting the one specific to that company.

What am I doing wrong?

By the way this is happening when using WAMP on my windows computer. I haven't tested it on my host yet (which uses Unix/Linux) for fear of deleting even more folders!
Reply


Messages In This Thread
Deleting folders and their content. - by keithmclaughlin - 04-20-2017, 09:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB