Day 1944 phpCMS2008同模型多个多图片字段上传出错的解决方法

网上的解决方法都是一大抄,经拆解得出以下结论(已测试通过):

一、故障原因

由于开发人员偷懒或疏忽,将所有多图片字段显示的div都使用了同一个名称file_div,而上传图片的原理是添加文件后向file_div中添加一个此图片的条目,由于以上原因,除第一个之外的多图片都跑到第一个里面去了,然后上传时由于field错误,除了最后一次添加的图片都会被忽略,造成只能上传1张的假象。

二、解决方法缩略版:

①修改include/fields/images/form.inc.php,大约在27行的位置:

将$data .= ‘<div id=”file_div”>’;
修改为$data .= ‘<div id=”file_div_’.$field.'”>’;

(即是按照fieldid区分对应的field)

②修改images/js/common.js,大约在279行位置,var Filenum=1;向下:
鉴于需要重新构造函数,将原有AddInputFile和DelInputFile函数内容直接删除,替换为:

function AddInputFile(Field, fileName)
{
	FileNum++;
	var fileTag = "<div id='file_"+FileNum+"'><input type='file' name='"+Field+"["+FileNum+"]' size='20' onchange='javascript:AddInputFile(\""+Field+"\", \""+Field+"\")'> <input type='text' name='"+Field+"_description["+FileNum+"]' size='20' title='名称'> <input type='button' value='删除' name='Del' onClick='DelInputFile("+FileNum+", 1);'></div>";
	var fileObj = document.createElement("div");
	fileObj.id = 'file_'+FileNum;
	fileObj.innerHTML = fileTag;
	if(arguments.length == 1)
	{
		document.getElementById("file_div").appendChild(fileObj);
	}else{
		document.getElementById("file_div_"+fileName).appendChild(fileObj);
	}
}

	function DelInputFile(FileNum, fileName)
	{
		var DelObj = document.getElementById("file_"+FileNum);
		if(arguments.length == 1)
	{
		document.getElementById("file_div").removeChild(DelObj);
	}else{
		document.getElementById("file_div_"+Field).removeChild(DelObj);
	}
}

重新登录后台,更新所有缓存,再打开有多个多图片字段的内容编辑时,便不会再发生以前的状况了。

注:所有评论将在审核通过后显示,请不要在评论内容的任何位置出现链接,否则您的评论将被自动移入回收站,且永远不会被复审。

All comments will be available after being manually reviewed, please do not include any links anywhere in your comment, otherwise your comment will be automatically deleted and are not eligible for review.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注