CodeIgniter Forums
delete_files() not working correctly in CI3 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: delete_files() not working correctly in CI3 (/showthread.php?tid=79831)



delete_files() not working correctly in CI3 - richb201 - 08-02-2021

This call is not working correctly. I'd like to delete uploads/richb2-gmail-com/ and all its subdirs. This my structure
uploads/richb2-gmail-com/thumbnails

        $szBucket_name = str_replace(array("@", "."), "-", $_SESSION['userid']);
        $ouputDirectory = '/app/assets/uploads/'.$szBucket_name.'/';
        delete_files($ouputDirectory,TRUE);   << $outputDirectory is 

/app/assets/uploads/richb201-gmail-com/
But when this runs it only deletes the following dir and it's files. It skips deleting /richb201-gmail-com
/app/assets/uploads/richb201-gmail-com/thumbnails


RE: delete_files() not working correctly in CI3 - paliz - 08-02-2021

[quote pid="389060" dateline="1627916219"]
 i use to for ci3 ,4 

PHP Code:
<?php namespace Modules\Common\Libraries;

use 
CodeIgniter\HTTP\Response;

class  CustomFileSystem
{
    protected string $error;

    public function __construct()
    {
        $this->error '';
    }

    /**
    * @return string
    */
    public function getError(): string
    
{
        return $this->error;
    }

    public function removeSingleFile($path)
    {
        try {

            if (file_exists($path)) {
                unlink($path);
            }


        } catch (\Exception $e) {
            $this->error $e->getMessage();

        }

    }


    public function removeMultipleFiles($path)
    {
        try {

            if (file_exists($path)) {
                unlink($path);
            }


        } catch (\Exception $e) {
            $this->error $e->getMessage();

        }

    }




[/quote]


RE: delete_files() not working correctly in CI3 - InsiteFX - 08-03-2021

Delete ALL Files and Subfolders from Folder in PHP


RE: delete_files() not working correctly in CI3 - richb201 - 08-04-2021

Thanks. I got that working now. My only problem is if the user exits the window by using X, my delete code doesn't run. Is there anyway to catch that a user is exiting via X ?


RE: delete_files() not working correctly in CI3 - InsiteFX - 08-05-2021

How to capture the browser window close event?


RE: delete_files() not working correctly in CI3 - richb201 - 08-05-2021

Thanks I will review that.