模板页面添加ifreme
<div style=' display: none;' >
     <iframe name ="uploadResponse_attachment" id= "uploadResponse_attachment"></iframe >
    <form id ="uploadForm_attachment" action= "<?php echo site_url('logistics/upload_chartering_attachment') ?>" target= "uploadResponse_attachment" method ="post" enctype= "multipart/form-data">
     <input type ="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value= "<?php echo $this->security->get_csrf_hash(); ?>" />
    </form >
</div>
 
对应js页面添加
//上传租船附件
function upload_attachment_chartering()
{
     $('#attachment_img_notice').show();
    var file = document.getElementById( "chartering_attachment");
    var uploadFormElement = document.getElementById("uploadForm_attachment" );
   
    uploadFormElement .appendChild(file);
    document.getElementById("attachment_img_div").innerHTML = '<a href="javascript:void(0)" class="btn_blue_26"><span>上传</span></a><input type="file" onchange="upload_attachment_chartering()" name="chartering_attachment" multiple="multiple" id="chartering_attachment">';
 
    //提交图片数据
    uploadFormElement .submit();
    uploadFormElement.removeChild( uploadFormElement.chartering_attachment);
}
 
//上传成功回掉
function upload_attachment_chartering_callback(file_path)
{
    $(".attachment_show_img").attr( 'src',file_path);
    $('#attachment_image').val(file_path);
    $('#attachment_img_notice').hide();
    $('.attachment_error').html( '');
    $('.attachment_error').hide();
}
 
//上传失败回掉
function upload_attachment_chartering_fail_callback(fail_remind)
{
     $(".attachment_show_img").attr( 'src', '/images/11.gif');
     $('#attachment_image').val( '');
     $('#attachment_img_notice').show();
    $('.attachment_error').html(fail_remind);
    $('.attachment_error').show();
}
 
public function _upload_chartering_attachment_post()
     {
           $data = upload_member_voucher('chartering_attachment' );
            if($data[ 'succ'] == 1){
                $file_path = $data[ 'file_path'];
                 echo "<script type='text/javascript'>parent.upload_attachment_chartering_callback('$file_path ')</script>";
           } else{
                $fail_reason = $data[ 'fail_reason'];
                 echo "<script type='text/javascript'>parent.upload_attachment_chartering_fail_callback('".$fail_reason. "')</script>";
           }
     }
 
function upload_member_voucher($form_file_id = '' ) {
            if (!$form_file_id) {
                 return;
           }
           $ci = &get_instance();
           $cert_dir = $ci-> config->item( 'cert_path') . '/';
           $day_dir = date( 'Ym');
           $physics_path = FCPATH . '..' . $cert_dir . $day_dir;
            if (!is_dir($physics_path)) {
                mkdir($physics_path, 0755);
           }
           $config[ 'upload_path'] = $physics_path; //文件上传目录
 
           $config[ 'encrypt_name'] = true;
           $config[ 'allowed_types'] = "gif|jpg|png|tif"; //文件类型
           $config[ 'max_size'] = "1048"; //最大上传大小
           $ci-> load->library( "upload", $config);
 
            if ($ci-> upload->do_upload($form_file_id)) { //表单中name="userfile"
                $data = $ci-> upload->data(); //返回上传图片的信息
                $res[ 'succ'] = 1;
                $res[ 'file_path'] = $cert_dir . $day_dir . '/' . $data['file_name'];
           } else{
                $res[ 'succ'] = 0;
                $res[ 'fail_reason'] = $ci->upload->display_errors();
           }
            return $res;
     }

通过ifreme实现文件上传的更多相关文章

  1. jquery.uploadify文件上传组件

    1.jquery.uploadify简介 在ASP.NET中上传的控件有很多,比如.NET自带的FileUpload,以及SWFUpload,Uploadify等等,尤其后面两个控件的用户体验比较好, ...

  2. 11、Struts2 的文件上传和下载

    文件上传 表单准备 要想使用 HTML 表单上传一个或多个文件 须把 HTML 表单的 enctype 属性设置为 multipart/form-data 须把 HTML 表单的method 属性设置 ...

  3. Java FtpClient 实现文件上传服务

    一.Ubuntu 安装 Vsftpd 服务 1.安装 sudo apt-get install vsftpd 2.添加用户(uftp) sudo useradd -d /home/uftp -s /b ...

  4. 小兔Java教程 - 三分钟学会Java文件上传

    今天群里正好有人问起了Java文件上传的事情,本来这是Java里面的知识点,而我目前最主要的精力还是放在了JS的部分.不过反正也不麻烦,我就专门开一贴来聊聊Java文件上传的基本实现方法吧. 话不多说 ...

  5. ,net core mvc 文件上传

    工作用到文件上传的功能,在这个分享下 ~~ Controller: public class PictureController : Controller { private IHostingEnvi ...

  6. Web开发安全之文件上传安全

    很长一段时间像我这种菜鸡搞一个网站第一时间反应就是找上传,找上传.借此机会把文件上传的安全问题总结一下. 首先看一下DVWA给出的Impossible级别的完整代码: <?php if( iss ...

  7. AutoIt实现Webdriver自动化测试文件上传

    在运用WebDriver进行自动化测试时,由于WebDriver自身的限制,对于上传文件时Windows弹出的文件选择窗口无法控制,通过在网上查找资料锁定使用AutoIt来控制文件上传窗口. Auto ...

  8. Struts的文件上传下载

    Struts的文件上传下载 1.文件上传 Struts2的文件上传也是使用fileUpload的组件,这个组默认是集合在框架里面的.且是使用拦截器:<interceptor name=" ...

  9. .JavaWeb文件上传和FileUpload组件使用

    .JavaWeb文件上传 1.自定义上传 文件上传时的表单设计要符合文件提交的方式: 1.提交方式:post 2.表单中有文件上传的表单项:<input type="file" ...

随机推荐

  1. 剑指offer 面试6题

    面试6题: 题目:从尾到头打印链表 输入一个链表,从尾到头打印链表每个节点的值. 解题代码: # -*- coding:utf-8 -*- # class ListNode: # def __init ...

  2. 【转】web.xml中load-on-startup的作用

    http://www.blogjava.net/xzclog/archive/2011/09/29/359789.html 如下一段配置,熟悉DWR的再熟悉不过了:<servlet>   ...

  3. docker多个容器连接 将 Rails 程序部署到 Docker 容器中

    在docker中使用MySQL数据库 https://yq.aliyun.com/articles/583765 将 Rails 程序部署到 Docker 容器中

  4. python之路(sed,函数,三元运算)

    python之路(sed,函数,三元运算) 一.sed集合 1.set无序,不重复序列 2.创建 se = {11,22,33,33,44} list() #只要是一个类加上()自动执行 list _ ...

  5. Django~1

    一 什么是web框架? 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统,简单地说,就是你用别人搭建好的舞台来做表演. 对于所有 ...

  6. 自定义Cell需要注意的问题

    使用xib创建cell时需要在设置单元格样式时使用[[NSBundel mainBundel] loadNibName:@“xib的文件名”owner:self option:nil][0]来初始化单 ...

  7. Mysql 主从复制搭建

    Mysql 主重复制搭建 Linux版本:Linux Centos 6.4 32位 Mysql版本:Mysql-5.6.38-linux-glibc2.12-i686 Mysql安装:Mysql安装教 ...

  8. 13.常见模块re-正则模块

    1.正则 正则表达式是计算机科学的一个概念,正则表通常被用来检索.替换那些符合某个模式(规则)的文本.也就是说使用正则表达式可以在字符串中匹配出你需要的字符或者字符串,甚至可以替换你不需要的字符或者字 ...

  9. StringTemplateLoader的用法

    作为一个模板框架,freemarker的功能还是很强大的.在模板处理方面,freemarker有多种形式,最常见的方式是将模板文件放在一个统一的文件夹下面,如下形式:Configuration cfg ...

  10. Netsh 命令详解

    1. help帮助指南 2. 常用命令介绍netsh interface ip show addressnetsh interface ip dumpnetsh interface ip dump & ...