简体   繁体   中英

Deleting a file from folder using PHP

I am trying to implement a way for user to delete files. I am using the code below but it doesn't delete the files. This file is under the root and i checked and made sure that it has permissions to allow users to do what they want, so i am thinking its the script:

   $sql = "select `File` from `documents` where `user_id` = '$userid'
   and `doid` = '$doid'";
  $query = mysql_query($sql) or die ("Error: ".mysql_error());

   while ($row = mysql_fetch_array($query)){

$fn = $row['File'];

  }
   mysql_free_result($query);

    unlink(/userstash/$fn);

unlink($file) is the correct function to delete a file.

Check if the $fn is filled. And try to use.

unlink('/userstash/' . $fn);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM