奥非域

WebPascal脚本模型教程 - 清理上传的图片

如何清理用户上传的图片呢?因为这些图片中,有一部分我们使用了,还有一部分是没有使用到的,它们就成为了垃圾,需要你去清理它们!

从1.4版本开始,增加了操作文件上传目录的几个函数,在2.0版本中,我们可以轻松的进行这样的操作了!代码如下:

<?
//连接 MSAccess 数据库的连接字符串
$s:=DBConn('mydb','DriverID=MSAcc;Database=.\db.mdb');

'开始删除文件...<br>'
$a:=getupfilelist('/');
if $a('r').count<>0 then
begin
	for $i:=0 to $a('r').count-1 do
	begin
		$x:=DBQuery('mydb','select fid from torder where fphoto=:p1',$a('r').($i));
		if $x.count<>0 then
		begin
			$a('r').($i)' 占用中,不删除!<br>';
		end else begin
			$a('r').($i);
			if deletefile($a('r').($i)) then
			begin
				' 文件删除成功!';
			end;
			'<br>'
		end;
	end;
end;
'开始删除空目录...<br>'
$a:=getupdirlist('/');
if $a('r').count<>0 then
begin
	for $i:=0 to $a('r').count-1 do
	begin
		if RemoveDir($a('r').($i)) then
		begin
			$a('r').($i)' 目录删除成功!';
		end else begin
			$a('r').($i)' 目录非空,不删除!';
		end;
		'<br>'
	end;
end;
?>