1

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

2
  • 3
    you're trying to unlink an array... RTLM: php.net/mysql_fetch_array then also go read up about SQL injection before you get your server pwn3d. Commented Feb 19, 2013 at 15:51
  • 2
    ... and the @ makes sure you don't see the error. Commented Feb 19, 2013 at 15:51

1 Answer 1

3

$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.

Sign up to request clarification or add additional context in comments.

3 Comments

@MihaiIorga thanks for answer, when is used the above code still nothing happened when i echo ('images/'.$image['file_name']); result is: images/ so its not taking file name.
@webdevelopersana take the code above again. I've updated.. you misspelled file_records on select
@MihaiIorga you are php genius. Thanks you all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.