Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unlink image in php

Tags:

php

i upload image to the server and save the path in data base. Now i want to delete that record and also the image with that record my code is

$id=$_GET['id'];
$select=mysql_query("select image from table_name where question_id='$id'");
$image=mysql_fetch_array($select);
@unlink($image['image']);
$result=mysql_query("delete from table_name where question_id='$id'");

when i echo $image['image']; this will give me

http://www.example.com/folder/images/image_name.jpeg
The record is deleted successfully but the image remains there on server.
like image 622
souce code Avatar asked Apr 19 '11 08:04

souce code


1 Answers

You'll have to use the path on your server to delete the image, not the url.

unlink('/var/www/test/folder/images/image_name.jpeg'); // correct

you should remove the @ before unlink(), in that case you would have seen the error-message saying "file not found" or something like that.

like image 167
oezi Avatar answered Oct 06 '22 04:10

oezi