导航首页 » 网站优化

dedecms织梦图集上传用图片名做注释

2023/03/11 12:26    魔司收录网    已浏览141次

dedecms织梦图集上传图片默认是要手动填写注释的,有时我们做好了产品图和图片名称,为了方便想让上传图片后自动获取图片名做注释,那下面的教程就非常有用了。
1、打开 \dede\swfupload.php 找到(注意,dede为默认后台的目录,请自行登录自己所在后台目录修改)

1 echo "FILEID:".$_SESSION['fileid'];

在它的上面加入

1 $file_snames = explode('.', $Filename);
2 $file_filename = $file_snames[count($file_snames)-2];
3 $_SESSION['file_filename'][$_SESSION['fileid']] = $file_filename;

继续找到
/************************
//删除指定ID的图片
*************************/
在它的上面加入

01 /************************
02 //生成注释
03 function GetThumbnail(){  }
04 *************************/
05 else if($dopost=='thumbalt')
06 {
07     if( empty($id) )
08     {
09         header('HTTP/1.1 500 Internal Server Error');
10         echo 'No ID';
11         exit(0);
12     }
13     if (!is_array($_SESSION['file_filename']) || !isset($_SESSION['file_filename'][$id]))
14     {
15         header('HTTP/1.1 404 Not found');
16         exit(0);
17     }
18     if($cfg_soft_lang=='utf-8') $file_filename = $_SESSION['file_filename'][$id];
19     else $file_filename = iconv( 'UTF-8', 'gb2312//IGNORE' , $_SESSION['file_filename'][$id]);
20     echo $file_filename;
21     exit(0);
22 }

2、打开 \dede\album_add.php 找到

1 $imginfo =  !empty(${'picinfook'.$k}) ? ${'picinfook'.$k} : '';

改成

1 $imginfo =  !empty(${'picinfook'.$k}) ? ${'picinfook'.$k} : $_SESSION['file_filename'][$k];

3、打开 \dede\album_edit.php 找到

1 $imginfo =  !empty(${'picinfook'.$k}) ? ${'picinfook'.$k} : '';

改成

1 $imginfo =  !empty(${'picinfook'.$k}) ? ${'picinfook'.$k} : $_SESSION['file_filename'][$k];

4、打开 \dede\js\handlers.js 找到

1 newImgDiv.innerHTML += '<div style="margin-top:10px">注释:<input type="text" name="picinfo'+albImg+'" value="" style="width:'+iptwidth+'px;" /></div>';

改成

1 newImgDiv.innerHTML += '<div style="margin-top:10px">注释:<input type="text" name="picinfo'+albImg+'" value="" style="width:'+iptwidth+'px;" id="picinput'+albImg+'" /><span id="picinfo'+albImg+'" style="display:none;"></span></div>';
2 var picinfo = document.getElementById('picinfo'+albImg);
3 var picinput = document.getElementById('picinput'+albImg);
4 var myajax = new DedeAjax(picinfo,false,false,"","","");
5 myajax.SendGet2('swfupload.php?dopost=thumbalt&id='+pid);
6 picinput.value = picinfo.innerHTML;
7 DedeXHTTP = null;

完成