sanainfotech
sanainfotech

Reputation: 691

delete image file from folder in server using php

How can i delete image file in my server folder called (images) using php i am trying the following code

<a href="delete.php? id=<?php echo $row_DetailRS1['id'];?>">Delete</a>

this take me to delete.php page

$id=$_GET['id'];            
$select = mysql_query("SELECT `file_name` FROM `flie_record WHERE `file_records`.`id` = '$id'");
$image  =mysql_fetch_array($select);
@unlink('images/'.$image);

nothing happening

Upvotes: 1

Views: 20037

Answers (1)

Mihai Iorga
Mihai Iorga

Reputation: 39704

$image is an array and you need to add the key:

$id = (int)$_GET['id'];            
$select = mysql_query("SELECT `file_name` FROM `file_records` WHERE `file_records`.`id` = '$id'");
$image  =mysql_fetch_array($select);
@unlink('images/'.$image['file_name']);

and (int) to $_GET['id'] - integer for MySQL injection hole.

Upvotes: 3

Related Questions