954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

deleting a file from folder

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 !");

mayreeh
Newbie Poster
21 posts since Oct 2011
Reputation Points: 10
Solved Threads: 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.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

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;
}

mayreeh
Newbie Poster
21 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

Remove the @ before unlink and see if it throws an error.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

nothing happens, no error, bt no deletion made

mayreeh
Newbie Poster
21 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

Echo the parameter in unlink, and check whether it is a valid file.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: