简体   繁体   中英

how to delete a file from a subfolder within a folder using php

I have to delete a file from the database and also to delete the file from the folder which is stored in server as files(folder)/newsletter(subfolder)/file1 using php.Iam using following code,the file is deleting from the database,but its not deleting from the folder,..plz help,thanks in advance.

my code is..

<?php

$id = intval($_REQUEST['id']);

include 'db/connection.php';

$sql1 = mysql_query("select * from newsletters where id=$id");
$results = mysql_fetch_array($sql);

if ($results["file"] != "") {

    $image = $results["file"];

    unlink('../files/newsletter/' . $image);
}

$sql = "delete from newsletters where id=$id";

$result = @mysql_query($sql);

if ($result) {
    echo json_encode(array('success' => true));
} else {
    echo json_encode(array('msg' => 'Some errors occured.'));
}

?>

请注意此路径,“ ../ files / newsletter /”应提及正确的路径,如果您的服务器基于ubuntu,则更改对filesnewsletter文件夹的权限。

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