From表单——模拟“伪”异步上传文件

前台页面:

    <iframe  name="upload_hidden_frame" id="upload_hidden_frame"frameborder="0" style="display: none;"></iframe>
    <form  action="<?php echo $base_url . $task; ?>"  method="post"  enctype="multipart/form-data" id="upload-form"  target="upload_hidden_frame" >
            <div class="file_url_div l">
                    <input id="file_url" name="file_url" type="text"/>
            </div>
            <div class="file_text_div l">
                    <input id="file_windows_btn" type="button" value="选择图片"/>
                    <input id="file_value"  name="file_value"  type="file"   style="display: none;"/>
            </div>
            <div class="clear"></div>
            <input  id="upload_submit"  type="submit"  href="javascript:void(0)"  style="display: none;"/>
        </form>

后台处理图片上传成功后的回调处理机制:
              if(move_uploaded_file($tmp_name,$new_url .$new_name)){
                    $width_height = getimagesize($new_url .$new_name);
                    $width = $width_height[0];
                    $height = $width_height[1];
                    $destination['result'] = true;
                    $destination['width'] = $width;
                    $destination['height'] = $height;
                    $destination['name'] = $name;
                    $destination['success']= '图片上传成功 !';
                    $destination['src'] = JUri::root(true) .'/media/com_projectfork/projectfork/upload_requirement_file/'.$new_name;
                }

            $result = "<script>window.parent. uploadCallback(".json_encode($destination).")</script>";
            echo $result;
            jexit();

前台JS获取回调信息:
            function  uploadCallback(data){   //data:后台回调数据,根据data获取的信息,可执行异步刷新的图片的效果
            if(data.result){
                var width = "";
                var img = "";
                jQuery("#upload_remind_div > #img_size_type").find("span").text("");
                jQuery("#upload_remind_div > #img_size_type").find("span").text(data.success);
                if(data.width>400){
                    width = "470";
                    img = jQuery("<img>",{"src":data.src }).css({
                        "width":width
                    });
                }
                else{
                    img = jQuery("<img>",{"src":data.src });
                }
                var cont = jQuery(window.frames["ke-edit-iframe-upload"].document).find("body");
                if(cont.length!=0){
                    var p = jQuery("<p></p>");
                    var a = jQuery("<a>文件名称:"+data.name+"</a>").css({
                        "margin-left":"auto",
                        "margin-right":"auto"
                    }).attr("href",data.src);
                    p.append(img);
                    cont.append(p).append(a);
                }
            }
            else{
                jQuery("#upload_remind_div > #img_size_type").find("span").text("");
                jQuery("#upload_remind_div > #img_size_type").find("span").text(data.src);
            }
        }















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值