
哈哈,清风其实也是采用这样的做发法的。正好看到有童鞋博客上有这样写。就顺手贴过来了。
if($result)
{
echo "上传成功!文件路径为:".$file2;
echo '<input name="img" type="hidden" value="'.$file2.'" id="img"/>';
echo'<script>parent.document.form1.img.value=document.getElementById("img").value;</script>';
}
文件上传成功后,把文件路径写入一个隐藏的域中(img),然后用DOM原理把隐藏域中的VALUE发送到父框架的表单form1的img文本框中: ok,再来看看清风的。 清风编辑器用了tinyMCE,所以有一点点不一样。 我的form页:
<script src="tiny_mce/tiny_mce.js" type="text/javascript"></script>
<script type="text/javascript">
// O2k7 skin
tinyMCE.init({
// General options
mode : "exact",
elements : "content",
theme : "advanced",
skin : "o2k7",
language : "zh",
relative_urls : false,
//....略过部分...
});
function InsertHtml(type,path){
type=type.toLowerCase()
switch(type){
case '.gif':
thecode = '<img src="'+path+'" alt=""/>';
break;
case '.jpg':
thecode = '<img src="'+path+'" alt=""/>';
break;
//......略过部分......
default :
thecode = '<a href="'+path+'" target="_blank">Download</a>';
break;
}
tinyMCE.execCommand('mceInsertContent',true,thecode);
}
</script>
iframe也就是在这个页面里了。 在我的iframe的提交给的php处理里:
$pasteJS = "<script type=text/javascript>n";
$pasteJS .= "parent.InsertHtml("" . $file_ext . "","" . $upload_src . "");n";
$pasteJS .= "</script>n";
echo $pasteJS;
于是上传的文件就跑到tinyMCE的编辑框里了。upload的文件路径也通过userdata会暂存起来,直到写入database。路径保存这块儿,也是在iframe的提交给的php处理文件里的,这里清风就不多写了。