Page 1 of 1

Trash can delete file

Posted: Tue 11. May 2004, 08:46
by stevenhanna6
Hi I just started using phpwcms on my website, and I must say its great so far. But I found one really annoying thing, it would not really delete a file from the trash can. Needless to say I will be running a website where large files will be uploaded and deleted all the time...so when a file is deleted I expect it to be gone and not taking up space. Now I couldn't find a fix for this problem so I just modified the code in act_file.php. Now it will delete the file and its info from the phpwcms_file table.

act_file.php

Code: Select all

if(isset($_GET["trash"])) {
	list($id, $wert) = explode("|", $_GET["trash"]);
	$id		= intval($id);
	$wert	= intval($wert);
	if($wert == 1 || $wert == 0) {
		$sql =  "UPDATE ".DB_PREPEND."phpwcms_file SET f_pid=0, ".
				"f_trash=".$wert.", f_changed=CONCAT_WS('|', f_changed, '".time()."'), ".
				"f_log=CONCAT_WS('\n', f_log, 'deleted by user ".aporeplace($_SESSION["wcs_user"])."') ".
				"WHERE f_id=".$id." AND f_kid=1 AND f_uid=".$_SESSION["wcs_user_id"];
		$result = mysql_query($sql, $db) or die ("error while moving file to trash");
	}else if($wert == 9)
	{
		$sql =  "SELECT * FROM ".DB_PREPEND."phpwcms_file ".
					"WHERE f_id=".$id;
		$result = mysql_query($sql, $db) or die ("error finding file");
		$myrow = mysql_fetch_array($result);
		$f_uid = $myrow["f_uid"];
		$f_ext = $myrow["f_ext"];
		$location = getenv('DOCUMENT_ROOT').$phpwcms["root"].$phpwcms["file_path"];
		$filename = $location .$f_uid ."/". $f_uid ."_". $id . ".".$f_ext ;
		unlink($filename);

		$sql1 =  "DELETE FROM ".DB_PREPEND."phpwcms_file ".
				"WHERE f_id=".$id;
		$result = mysql_query($sql1, $db) or die ("error while moving file to trash");

	}
}

Posted: Sat 22. May 2004, 08:23
by evan
This is pretty nice, thanks for sharing this. I've just been deleting left-over files by hand after things start to fill up, which can be kind of tedious...

The only thing that's needed now is the ability to delete lots of files at once, clicking the trash can a million times gets old fast.

Posted: Sat 22. May 2004, 14:03
by pSouper
thanks for this, i too have a hi turnover of images etc and this will surly help my site's footprint.

you wouldn'y have a reto active 'clean_up DB' function too would you?
I have a huge amount of images, articles, menu's etc that are resudue in my database that I have no further need for.

I think a recurrsive delete state = 9 then delete type function may sort most out.
I'm not sure if that would reclaim previously use alias's.

(I belive both are planned by Oliver soon: yippie :D)

Posted: Wed 26. May 2004, 01:13
by Oliver Georgi
above code will fail if you have problems with DOCUMENT_ROOT var.

Oliver

Posted: Tue 8. Jun 2004, 08:13
by marses
I had to add "/" in a row below to make it work:

$location = getenv('DOCUMENT_ROOT')."/".$phpwcms["root"].$phpwcms["file_path"];