I am using code-igniter. In my project i would like to delete the specific image in folder(artical_images). If i try to use delete_files() option it deletes all the images in the folder when use the code like,
public function delete_post($value='$id')
{
$query=$this->db->query("select artical_profile from articals where artical_id='$value' ");
$img_name=$query->result()[0]->artical_profile;
//echo $img_name;
delete_files('./artical_images/',TRUE);
// $this->db->where('artical_id',$value);
//$this->db->delete('articals');
exit();
}
But when i include the specific image name taken from db and include with delete file path it doesn't work.The code is below,
public function delete_post($value='$id')
{
$query=$this->db->query("select artical_profile from articals where artical_id='$value' ");
$img_name=$query->result()[0]->artical_profile;
//echo $img_name;
delete_files('./artical_images/$img_name',TRUE);
// $this->db->where('artical_id',$value);
//$this->db->delete('articals');
exit();
}
even i included the realpath option it also not works,
public function delete_post($value='$id')
{
$query=$this->db->query("select artical_profile from articals where artical_id='$value' ");
$img_name=$query->result()[0]->artical_profile;
$img_name=realpath(APPPATH . '/artical_images/$img_name');
delete_files('$img_name',TRUE);
echo $img_name;
// $this->db->where('artical_id',$value);
//$this->db->delete('articals');
exit();
}
please give some idea to delete the files,
delete_files
uses a directory path to delete all the files in the directory. It applies the recursive unlink
command to delete files.
To delete particular file, You can use unlink
with the proper file path.
eg unlink(FILE_PATH);
$this->load->helper("file");
delete_files($path);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.