织梦侠
WWW.2L3.NET

dedecms织梦让模型里的图片字段支持本地上传

本地上传效果


修改教程
1、打开 \dede\js\main.js 找到
  1. function SeePicNew(f, imgdid, frname, hpos, acname)
  2. {
  3. 中间代码...
  4. }
把这整个函数改成
  1. function SeePicNew(f, imgdid, frname, hpos, acname, formname, picname, picvalue)
  2. {
  3. var formname = formname ? formname : 'save';
  4. var picname = picname ? picname : 'picname';
  5. var picvalue = picvalue ? picvalue : 'picname';
  6. var imgdid = imgdid ? imgdid : 'divpicview';
  7. var newobj = null;
  8. if(f.value=='') return ;
  9. vImg = $Obj(imgdid);
  10. picnameObj = document.getElementById(picname);
  11. nFrame = $Nav()=='IE' ? eval('document.frames.'+frname) : $Obj(frname);
  12. nForm = f.form;
  13. if(nForm.detachEvent) nForm.detachEvent("onsubmit", checkSubmit);
  14. else nForm.removeEventListener("submit", checkSubmit, false);
  15. if(picname == 'picname') var picname = 'litpic';
  16. nForm.action = 'archives_do.php?litpic='+picname+'&picname='+picvalue+'&divpicview='+imgdid;
  17. nForm.target = frname;
  18. nForm.dopost.value = 'uploadLitpic';
  19. nForm.submit();
  20. picnameObj.value = '';
  21. newobj = $Obj('uploadwait');
  22. if(!newobj)
  23. {
  24. newobj = document.createElement("DIV");
  25. newobj.id = 'uploadwait';
  26. newobj.style.position = 'absolute';
  27. newobj.className = 'uploadwait';
  28. newobj.style.width = 120;
  29. newobj.style.height = 20;
  30. newobj.style.top = hpos;
  31. newobj.style.left = 100;
  32. newobj.style.display = 'block';
  33. document.body.appendChild(newobj);
  34. newobj.innerHTML = '<img src="images/loadinglit.gif" width="16" height="16" alit="" />上传中...';
  35. }
  36. newobj.style.display = 'block';
  37. nForm.action = acname;
  38. nForm.dopost.value = formname;
  39. nForm.target = '';
  40. }
2、打开 \dede\archives_do.php 找到
  1. else if($dopost=="uploadLitpic")
  2. {
  3. 中间代码省略...
  4. }
整个改成
  1. else if($dopost=="uploadLitpic")
  2. {
  3. $fname = $_GET['litpic'] ? $_GET['litpic'] : 'litpic';
  4.     $upfile = AdminUpload($fname, 'imagelit', 0, true );
  5.     if($upfile=='-1')
  6.     {
  7.         $msg = "<script language='javascript'>
  8.                 parent.document.getElementById('uploadwait').style.display = 'none';
  9.                 alert('你没指定要上传的文件或文件大小超过限制!');
  10.             </script>";
  11.     }
  12.     else if($upfile=='-2')
  13.     {
  14.         $msg = "<script language='javascript'>
  15.                 parent.document.getElementById('uploadwait').style.display = 'none';
  16.                 alert('上传文件失败,请检查原因!');
  17.             </script>";
  18.     }
  19.     else if($upfile=='0')
  20.     {
  21.         $msg = "<script language='javascript'>
  22.                 parent.document.getElementById('uploadwait').style.display = 'none';
  23.                 alert('文件类型不正确!');
  24.             </script>";
  25.     }
  26.     else
  27.     {
  28.          if(!empty($cfg_uplitpic_cut) && $cfg_uplitpic_cut=='N')
  29.          {
  30.                  $msg = "<script language='javascript'>
  31.                     parent.document.getElementById('uploadwait').style.display = 'none';
  32.                     parent.document.getElementById('{$_GET[picname]}').value = '{$upfile}';
  33.                     if(parent.document.getElementById('{$_GET[divpicview]}'))
  34.                     {
  35.                         parent.document.getElementById('{$_GET[divpicview]}').style.width = '150px';
  36.                         parent.document.getElementById('{$_GET[divpicview]}').innerHTML = \"<img src='{$upfile}?n' width='150' />\";
  37.                     }
  38.                 </script>";
  39.          }
  40.          else
  41.          {
  42.                $msg = "<script language='javascript'>
  43.                     parent.document.getElementById('uploadwait').style.display = 'none';
  44.                     window.open('imagecut.php?f={$_GET[picname]}&isupload=yes&file={$upfile}', 'popUpImagesWin', 'scrollbars=yes,resizable=yes,statebar=no,width=800,height=600,left=150, top=50');
  45.                 </script>";
  46.          }
  47.     }
  48.     echo $msg;
  49.     exit();
  50. }
3、打开 \include\customfields.func.php 找到
  1. $innertext = "<input type='text' name='$fieldname' id='$fieldname' style='width:300px' class='text' /> <input name='".$fieldname."_bt' type='button' class='inputbut' value='浏览...' onClick=\"SelectImage('form1.$fieldname','big')\" />\r\n";
改成
  1. $innertext = "<input name='{$fieldname}' type='text' id='{$fieldname}' style='width:300px' value='' /><input type='button'  value='本地上传' style='width:70px;cursor:pointer;' /><iframe name='upmy{$fieldname}fra' id='upmy{$fieldname}fra' src='' width='200' height='200' style='display:none'></iframe><span class='litpic_span'><input name='my{$fieldname}' type='file' id='my{$fieldname}' onChange=\"SeePicNew(this, 'divmy{$fieldname}view', 'upmy{$fieldname}fra', 165, '', 'save', 'my{$fieldname}', '{$fieldname}');\" size='1' class='np coolbg' style='cursor:pointer;height:20px;margin-left:-20px;opacity:0;width:85px;'/></span> <input name='".$fieldname."_bt' type='button' class='inputbut' value='浏览...' onClick=\"SelectImageN('form1.$fieldname','big','$fieldname')\" /> <div id='divmy{$fieldname}view' class='divpre' style='display:inline-block;vertical-align:middle'></div>\r\n";
继续找到
  1. $innertext = "<input type='text' name='$fieldname' value='$fvalue' id='$fieldname' style='width:300px'  class='text' /> <input name='".$fieldname."_bt' class='inputbut' type='button' value='浏览...' onClick=\"SelectImage('form1.$fieldname','big')\" />\r\n";
有2处,都改成
  1. $imgstr = ($fvalue=='') ? '' : "<img src='{$fvalue}' width='150'>";
  2. $innertext = "<input type='text' name='$fieldname' value='$fvalue' id='$fieldname' style='width:300px'  class='text' /><input type='button'  value='本地上传' style='width:70px;cursor:pointer;' /><iframe name='upmy{$fieldname}fra' id='upmy{$fieldname}fra' src='' width='200' height='200' style='display:none'></iframe><span class='litpic_span'><input name='my{$fieldname}' type='file' id='my{$fieldname}' onChange=\"SeePicNew(this, 'divmy{$fieldname}view', 'upmy{$fieldname}fra', 165, '', 'save', 'my{$fieldname}', '{$fieldname}');\" size='1' class='np coolbg' style='cursor:pointer;height:20px;margin-left:-20px;opacity:0;width:85px;'/></span> <input name='".$fieldname."_bt' class='inputbut' type='button' value='浏览...' onClick=\"SelectImage('form1.$fieldname','big')\" /> <div id='divmy{$fieldname}view' class='divpre' style='display:inline-block;vertical-align:middle'>{$imgstr}</div>\r\n";
完结。
转载请注明文章来自织梦侠[Dedediy]作者的-dedecms织梦让模型里的图片字段支持本地上传
联系作者
取消
这个作者很懒什么也没留下!
打赏作者
取消

Dedediy:感谢您的支持,我会继续努力的!

扫码支付
扫码打赏,建议金额1-10元

打开支付宝扫一扫,即可进行扫码打赏哦

提醒:打赏金额将直接进入对方账号,无法退款,请您谨慎操作。