模板页面添加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. [笔记]一道C语言面试题:IPv4字符串转为UInt整数

    题目:输入一个IPv4字符串,如“1.2.3.4”,输出对应的无符号整数,如本例输出为 0x01020304. 来源:某500强企业面试题目 思路:从尾部扫描到头部,一旦发现无法转换,立即返回,减少无 ...

  2. Android开发BUG及解决方法1

    错误描述: 问题1: Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.Android. ...

  3. 【leetcode刷题笔记】Interleaving String

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = ...

  4. 【Tech】SQL Server2008使用笔记

    1.64位win7系统报错“未在本地计算机上注册 Microsoft.ACE.OLEDB.12.0 ”. 解决方法:从这个网址下载和安装一个驱动http://www.microsoft.com/zh- ...

  5. Shell编程之循环控制及状态返回值

    1.break.continue.exit.return的对比 break.continue在条件语句和循环语句中用于控制程序走向: exit用于终止所有语句并退出当前脚本,还可以返回上一次程序或命令 ...

  6. Eclipse与Tomcat的集成(无插件)

    1.下载Eclipse(https://www.eclipse.org/downloads/)和Tomcat(http://tomcat.apache.org/),具体的安装略: 2.打开Eclips ...

  7. 【bzoj1260】涂色paint[CQOI2007](区间dp)

    题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1260 这道题其实和codeforces607B有点像,然而做过原题的我居然没看出来.. ...

  8. jquery下json数组的操作用法实例

    jquery下json数组的操作用法实例: jquery中操作JSON数组的情况中遍历方法用的比较多,但用添加移除这些好像就不是太多了. 试过json[i].remove(),json.remove( ...

  9. 解决:SyntaxError: Non-ASCII character in file

    今天尝试用monkeyrunner脚本在夜神模拟器上安装并截图QQ,但是遇到了一些问题: from com.android.monkeyrunner import MonkeyRunner, Monk ...

  10. hdu 5244 inverse(分治¥)

    inverse Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...