Trash can delete file

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
stevenhanna6
Posts: 1
Joined: Tue 11. May 2004, 08:36
Contact:

Trash can delete file

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

	}
}
evan
Posts: 31
Joined: Sun 28. Mar 2004, 22:57

Post 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.
User avatar
pSouper
Posts: 1552
Joined: Tue 11. Nov 2003, 15:45
Location: London
Contact:

Post 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)
User avatar
Oliver Georgi
Site Admin
Posts: 9905
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

above code will fail if you have problems with DOCUMENT_ROOT var.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
marses
Posts: 26
Joined: Wed 5. Nov 2003, 09:53
Location: Dorking, England

Post by marses »

I had to add "/" in a row below to make it work:

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