I done delete image url from database with following code, but is not delete file image from upload path, how can delete file from upload path with url it in database (both together)?
This php is just for delete url from database:
$delete = $this -> input -> post('checked');
foreach($delete as $val) {
$this - > db - > delete($this - > _table, array('id' = > $val));
}
Update:
I have error in use of following code.
$id = '166';
$query = $this - > db - > get_where('hotel_image', array('id' = > $id));
if ($query - > num_rows() > 0) {
$res = $query - > row();
unlink(base_url(uploads/$res - > images));//This is line 161
}
$this - > db - > delete('hotel_image', array('id' = > $id));
Error:(my images are in this pach: http://example.com/uploads/)
A PHP Error was encountered
Severity: Notice
Message: Use of
undefined constant uploads – assumed ‘uploads’
Filename: user/dence.php
Line Number: 161A PHP Error was encountered
Severity: Warning
Message:
unlink() [function.unlink]: http does not allow unlinking
Filename: user/dence.php
Line Number: 161
You need to use unlink() to delete a file from disk, just pass the filename as parameter.
Something like (this is simplified code. You might want to check the path from DB is complete or else add the rest.):