PHP unlock function

This is the code

$query = mysql_query("SELECT avatar FROM users WHERE UserID = ".$userID.""); $row = mysql_fetch_array($query); $user_avatar = trim($row['avatar']); unlink($user_avatar); 

but for some reason I get this error. Warning: unlink ();

why is $ user_avatar returned empty? and if I echo it shows t_cabbbccebbfhdb.jpg

+7
source share
3 answers

disconnect delete files, while unset - for variables.

If the variable returns empty, the query may not return any records. Did you try to execute the request manually?

+12
source
 $query = mysql_query("SELECT avatar FROM users WHERE UserID = ".$userID.""); $row = mysql_fetch_array($query); $user_avatar = trim($row['avatar']); unset($user_avatar); //if you want to unlink file then if(!empty($user_avatar)) { unlink($home.$user_avatar); // $yourFile should have full path to your file } 
+1
source

In PHP, unlink is used to delete a file, make sure you provide the correct path. see here http://se.php.net/unlink

try disabling the variables. http://se.php.net/manual/en/function.unset.php

0
source

All Articles