Deleting folders and their content. |
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) I then load the file helper and call the delete_files function: PHP Code: $this->load->helper('file'); 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!
After your method call in $company_folder you will have a string like that:
public_html/htdocs/uploads/731e315adc887be41cc84be0f5c73f76 This directory should be deleted with all content ... can you post yourdelete_files method. Your problem should be there ...
@Rufnex, he is using the delete_files function from CI's File Helper
My guess is that the model is returning public_html/htdocs/uploads and not public_html/htdocs/uploads/731e315adc887be41cc84be0f5c73f76
The $company_folder does have the path to the correct folder to delete.
As I said I'm using WAMP so this is the path I get when testing it: C:\wamp64\www\foresight\public\uploads\731e315adc887be41cc84be0f5c73f76
Try to add a / to the end of your path:
C:\wamp64\www\foresight\public\uploads\731e315adc887be41cc84be0f5c73f76\
Try to remove the folder and content with nativ php .. if there is the same behavior you must have a config, logic or error. For e.g. like that:
Code: function recursiveRmDir($dir)
(04-23-2017, 10:39 AM)Rufnex Wrote: Try to remove the folder and content with nativ php .. if there is the same behavior you must have a config, logic or error. For e.g. like that: Same result. All folders inside the uploads folder got deleted. It must be a windows thing. I'm going to try it on my hosts server. |
Welcome Guest, Not a member yet? Register Sign In |