本帖最后由 putersham 于 2009-9-8 14:30 编辑
http://blog.sina.com.cn/s/blog_3f1a25310100en8j.html
这一篇就是处理图片了
废话不说
首先在config.php 中增加备份目录路径
$_SC['attachdir_bak'] = './attachment_bak/'; //附件本地备份保存位置(服务器路径, 属性 777, 必须为 web 可访问到的目录, 相对目录务必以 "./" 开头, 末尾加 "/")
$_SC['attachurl_bak'] = 'attachment_bak/'; //附件本地备份URL地址(可为当前 URL 下的相对地址或 http:// 开头的绝对地址, 末尾加 "/")
手工在根目录下创建文件夹 文件夹名为 :attachment_bak 如果是服务器上需要分配相应的权限
其次是增加自动生成备份子目录
修改 function_cp.php中的 function getfilepath($fileext, $mkdir=false) 函数
在 if($mkdir) {}这个判断里的最后加上代码 增加后的 if($mkdir) {}如下
if($mkdir) {
$newfilename = $_SC['attachdir'].'./'.$name1;
if(!is_dir($newfilename)) {
if(!@mkdir($newfilename)) {
runlog('error', "DIR: $newfilename can not make");
return $filepath;
}
}
$newfilename .= '/'.$name2;
if(!is_dir($newfilename)) {
if(!@mkdir($newfilename)) {
runlog('error', "DIR: $newfilename can not make");
return $name1.'/'.$filepath;
}
}
$newfilename_bak = $_SC['attachdir_bak'].'./'.$name1;
if(!is_dir($newfilename_bak)) {
if(!@mkdir($newfilename_bak)) {
runlog('error', "DIR: $newfilename_bak can not make");
return $filepath;
}
}
$newfilename_bak .= '/'.$name2;
if(!is_dir($newfilename_bak)) {
if(!@mkdir($newfilename_bak)) {
runlog('error', "DIR: $newfilename_bak can not make");
return $name1.'/'.$filepath;
}
}
}
然后就是修改 function_delete.php 中的function deletepicfiles($pics)这个函数
将以下代码
if(!@unlink($file)) {
runlog('PIC', "Delete pic file '$file' error.", 0);
}
if($pic['thumb']) {
if(!@unlink($file.'.thumb.jpg')) {
runlog('PIC', "Delete pic file '{$file}.thumb.jpg' error.", 0);
}
}
替换为
//文件地址
$file_path = $file;
$file_bak_path = $_SC['attachdir_bak'].$pic['filepath'];
if ($_GET['act']=='recycled') $file_path = $_SC['attachdir_bak'].$pic['filepath'];
if ($_GET['act']<>'recycled'){
//清理重复的备份文件
if (file_exists($file_bak_path)) unlink($file_bak_path);
//移动文件,代替删除动作
if(!@rename($file,$file_bak_path)) {
runlog('PIC', "Delete pic file '$file' error.", 0);
}
if($pic['thumb']) {
//清理重复的备份文件
if (file_exists($file_bak_path.'.thumb.jpg')) unlink($file_bak_path.'.thumb.jpg');
if(!@rename($file.'.thumb.jpg',$file_bak_path.'.thumb.jpg')) {
runlog('PIC', "Delete pic file '{$file}.thumb.jpg' error.", 0);
}
}
}else{
//删除文件
if(!@unlink($file_path)) {
runlog('PIC', "Delete pic file '$file' error.", 0);
}
if($pic['thumb']) {
if(!@unlink($file_path.'.thumb.jpg')) {
runlog('PIC', "Delete pic file '{$file}.thumb.jpg' error.", 0);
}
}
}
这样 当我们上传图片时会自动在备份文件夹内生成对应的图片路径文件夹,以备备份之用
在删除时会用文件移动动作代替原有的删除动作,将文件移动到备份文件夹内
接下来就是显示回收站内的图片
首先是管理后台,修改 admincp.php
在 include_once template("admin/tpl/$acfile");之前加上如下代码:
//回收站图片的显示
if ($list){
for ($i=0;$i<count($list);$i++){
if ($_GET["act"]=="recycled") $list[$i][pic] = str_replace('attachment','attachment_bak',$list[$i][pic]);
if ($_GET["act"]=="recycled") $list[$i][bigpic] = str_replace('attachment','attachment_bak',$list[$i][bigpic]);
}
}
还有从管理后台点图片后到相册,修改space_album.php
在两次出现的 include_once template("space_album_pic");之前加上地址处理:
//回收站图片的显示
if ($list && $_GET["act"]=="recycled" && preg_match("/admincp\.php/", empty($_SERVER['HTTP_REFERER'])?'' : $_SERVER['HTTP_REFERER'])){
for ($i=0;$i<count($list);$i++){
$list[$i][pic] = str_replace('attachment','attachment_bak',$list[$i][pic]);
$act = 'recycled';
}
}
还有模板文件 template\default\space_album_view.htm
<a href="space.php?uid=$value[uid]&do=$do&picid=$value[picid]"><img src="$value[pic]" alt="" /></a>
改为
<a href="<!--{if $act == recycled}-->./attachment_bak/$value[filepath]<!--{else}-->space.php?uid=$value[uid]&do=$do&picid=$value[picid]<!--{/if}-->"<!--{if $act == recycled}--> target="_blank"<!--{/if}-->><img src="$value[pic]" alt="" /></a>
好了 管理后台删除相册或者图片时,图片文件自动移动至回收文件夹,且正常显示回收文件夹内的图片了. |