Welcome Guest, Not a member yet? Register   Sign In
How to delete a file not folder?
#1

[eluser]bobcute[/eluser]
I have this code:
Code:
function project_files_delete() {

        $this->Project_files->get_entry($this->uri->segment(3));
        
        if ($this->Project_files->project_file_type = '.jpg' || $this->Project_files->project_file_type = '.png' || $this->Project_files->project_file_type = '.gif') {
            delete_files('.uploads/'.$this->Project_files->project_id.'/thumbnail/'.$this->Project_files->project_file_filename);
            delete_files('.uploads/'.$this->Project_files->project_id.'/'.$this->Project_files->project_file_filename);
         } else {
            delete_files('.uploads/'.$this->Project_files->project_id.'/'.$this->Project_files->project_file_filename, true);
         }
        $this->Project_files->delete_entry($this->uri->segment(3));
        redirect('portfolio/project_filesview', 'refresh');
    }

I'm sure that those files are existing in the folder.

ex.
Code:
[root]/uploads/3/file.doc
for files
ex.
Code:
[root]/uploads/3/thumbnail/image.jpg
for image

The deletion of the row in the database record is successful, but the file in the directory is still existing..

I'm using XAMPP on WINDOWS VISTA so I think I have no problem on file or folder permission.

Any help?
#2

[eluser]bobcute[/eluser]
It's ok now I use unlink... I'd just assumed that delete_files function also delete a single file....
#3

[eluser]allancaps[/eluser]
hi, i'm at a total loss here... i know we need to use unlink to delete files from the CI folders, but forgive me for having to ask this noob question... where do you use the unlink function? is it in the controller or the model? thanks!
#4

[eluser]mddd[/eluser]
Wherever you want. It is a normal php function. You can call it from any script.
#5

[eluser]allancaps[/eluser]
I have this code:
Code:
function deleteAttachment($id,$filename)
{
  unlink('.uploads/forum/'.$filename);
  $this->db->where('id', $id);
  $this->db->delete('forum_files');
}
basically everythings going great, i can delete from the db (mySQL), but can’t seem to delete the files in CI’s uploads folder. Any part of the unlink code I might have missed? thanks in advance! (again sorry for having posted on the wrong discussion board…)
#6

[eluser]mddd[/eluser]
Are the rights set correctly (so: does the webserver have write-access to the file?)
Is the path correct? If you are not sure what the current path of your script is, check with the 'getcwd()' function.
The path must be correct, relative to the position of the executing script (usually index.php in the root of the CI structure).
#7

[eluser]allancaps[/eluser]
here’s the absolute path… http://localhost/uploads/forum/test_upload_2.txt
I’ve even included the file_helper in the autoload function. and yes, there is complete access—rw to the folder… smile) I’m kinda stuck here… thanks for the help… Smile
#8

[eluser]mddd[/eluser]
Your path has '/uploads' in it. In your code it says '.uploads'.
So you are trying to delete something in the '.uploads' folder that may not even exist on your system.
#9

[eluser]allancaps[/eluser]
but is it really that? i mean, i have tried '/uploads/forum/', 'uploads/forum' and all others, but it doesn't seem to work. i have been able to upload to the folder, which suggests i can write to it, and i can delete from the db, but this I'm having trouble with... hmmm... are there any other settings that I might not have set? sorry for having all these questions... i have only been using CI for a month or so... but i'm loving it! thanks again.
#10

[eluser]danmontgomery[/eluser]
unlink() uses a system path, not a web path.




Theme © iAndrew 2016 - Forum software by © MyBB