CodeIgniter Forums

Full Version: delete_files function does not work me
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, Everybody

I am using Codeigniter 3.6 .

I cant understand what wrong i have done .
 


PHP Code:
public function delete_photo(){

  
$this->load->helper('file');

  
delete_files(base_url("uploads/".$_POST['old_photo'])); 



Please guide me 

Thanks
(05-09-2016, 12:59 PM)nkhan Wrote: [ -> ]Hello, Everybody

I am using Codeigniter 3.6 .

I cant understand what wrong i have done .
 


PHP Code:
public function delete_photo(){

 
 $this->load->helper('file');

 
 delete_files(base_url("uploads/".$_POST['old_photo'])); 



Please guide me 

Thanks
delete_files() deletes ALL files contained in the suppliedpath. To delete single file use/refer this link http://php.net/manual/en/function.unlink.php
1. CodeIgniter 3.6 doesn't exist.
2. Files are deleted from file-system paths, not from URLs.
https://en.wikipedia.org/wiki/Directory_...sal_attack

Also, I think, in $_POST it would be safer if it is possible you to identify the file to be deleted with a database id than with the file name directly.
(05-10-2016, 07:06 AM)ivantcholakov Wrote: [ -> ]https://en.wikipedia.org/wiki/Directory_...sal_attack

Also, I think, in $_POST it would be safer if it is possible you to identify the file to be deleted with a database id than with the file name directly.

Hi @ivantcholakov

Actually i want to know is there any  predefined function for delete a single file(it may be a pdf / doc/ image) in CI is exist or not. I know unlink() 

which is used to delete the file but it is core function of PHP. 

Please let me know.
(05-10-2016, 08:44 AM)nkhan Wrote: [ -> ]
(05-10-2016, 07:06 AM)ivantcholakov Wrote: [ -> ]https://en.wikipedia.org/wiki/Directory_...sal_attack

Also, I think, in $_POST it would be safer if it is possible you to identify the file to be deleted with a database id than with the file name directly.

Hi @ivantcholakov

Actually i want to know is there any  predefined function for delete a single file(it may be a pdf / doc/ image) in CI is exist or not. I know unlink() 

which is used to delete the file but it is core function of PHP. 

Please let me know.

And that unlink() is a native PHP function makes it bad somehow?
CodeIgniter doesn't have a single-file-delete function exactly because PHP already provides one out of the box.