0

hre is my code for deleting a file, wats missing?

$getFields($fields);
$infoFile = $doc->getFileInfo($file);

$title = _l("Delete a document");

if ($action == "dodelete" && $file)
{
    if ($doc->hasRight($_SESSION["Sid_user"], "d", $dir))
    {
        if (!$doc->deleteFile($file))

            $error = $doc->errstr();
        else
            $error = _l("Document successfully deleted !");
    }
    else
        $error = _l("You cannot delete documents !");

Edited by Nick Evan: Fixed formatting

2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by pritaeas
0

Hard to say, I assume it's not working ? If the file is not deleted, check if $file contains a full path, or a relative one. The problem could be in deleteFile(), so show what it does.

0

its colling this fuction... yet not deleting, ie the previous code colls the following code.

function deleteFile($id_file) {
$infoFile = $this->getFileInfo($id_file);
$folderPath = $this->folderPath($infoFile["id_folder"]);

if (substr($infoFile["file_name"], 0, 3) == ".ht") {
$this->error = 6;
return false;
}

if (!file_exists($this->root . "files" . $folderPath . SEP . $infoFile["file_name"])) {
$q = "UPDATE " . TABLE_PREFIX . "files SET file_flag = 1 WHERE id_file = '" . $id_file . "'";
query($q);
$this->error = 6;
return false;
}

if (@unlink($this->root . "files" . $folderPath . SEP . $infoFile["file_name"])) {
$q = "DELETE FROM " . TABLE_PREFIX . "files WHERE id_file = '" . $id_file . "'";
query($q);

$q = "OPTIMIZE TABLE " . TABLE_PREFIX . "files";
query($q);

$this->updateFolderSize($infoFile["id_folder"], $infoFile["file_size"], "-");
$this->updateFolderTime($infoFile["id_folder"]);
return true;
}
return false;
}

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.