Welcome Guest, Not a member yet? Register   Sign In
deleting files with delete_files() in helper
#1

(This post was last modified: 09-09-2020, 10:39 AM by richb201.)

I have two files I am trying to delete programmatically. Here is how I am doing it

$file='/app/assets/uploads/files/'.$user->file_url;
$iRc=delete_files($file);  //delete the pdf
//delete the thumbnail
$iRc=delete_files('/app/'.$user->thumbnail_url);


I am running in docker. Both these deletes fail ($iRc=false). So I tried to delete from the cli and that seems to work. I did open a bin/bash session into the running container. I also took a look at the permissions and I see that although I am the owner (ME) and have read/write permissions, my application is running under group richb201 (I think) and that the group has "read only" permissions. How can I be sure that my app is under richb201, btw? How can I change the permissions programatically so that my app can rm these two. I am under Ubuntu. 
proof that an old dog can learn new tricks
Reply
#2

chmod
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

thx. I found it. But it is not working. Could be because the owner is www.
proof that an old dog can learn new tricks
Reply
#4

chmod 775 or at least 664 should do the job.
Reply
#5

(This post was last modified: 09-10-2020, 03:41 PM by InsiteFX.)

Check to see if there is a .htaccess file in the app folder.

You should have the assets folder in the root along with index.php

After looking at the helper what your doing is wrong the helper deletes
all the files in a folder.

This is what you want not tested just figure out the right path.

PHP Code:
$path base_url('assets/uploads/files/').$user->file_url;

if(@
unlink($path))
{
    echo "Deleted file ";
}
else
{
    echo "File can't be deleted";

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

Turned out that I didn't know how to use delete_files. It deletes all the files of a directory, when I just wanted to delete a specific file.

Here is the solution that worked.
$cmd = "rm ". '/app/assets/uploads/files/'. $user->file_url;
$result = shell_exec($cmd);

//delete thumbnail
$cmd = "rm ". '/app/'. $user->thumbnail_url;
shell_exec($cmd);
proof that an old dog can learn new tricks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB