• uploadify批量上传时url出现%EF%BB%BF


    自己遇到的问题想办法解决了,后来上google了一下,找到了老外的方法。

    直接上代码吧

    js:

     1 <script type="text/javascript">
     2 $(document).ready(function() {
     3    $('#file_upload').uploadify({
     4      'height'    : 30,
     5      'width'     : 100,
     6      'buttonImg' : '<?=base_url()?>style/images/buttons/button_dodaj_gray.png',
     7      'cancelImg' : '<?=base_url()?>style/js/uploadify/cancel.png',
     8      'wmode'     : 'transparent',
     9      'onComplete': function(event, ID, fileObj, response, data) {
    10           if( response != "ERROR" )
    11           {
    12               var imageSrc = "";
    13               //imageSrc = "/ads_images_temp/";
    14               imageSrc = response;
    15               $('.image_container').html('<img src="<?=base_url()?>'+imageSrc+'"></img>');
    16           }
    17      },
    18      'fileExt'   : '*.jpg;*.jpeg;*.png;*.gif',
    19      'displayData': 'percentage',
    20      'multi'     : false,
    21      'uploader'  : '<?=base_url()?>style/js/uploadify/uploadify.swf',
    22      'script'    : '/tools/upload/product/glavna',
    23 
    24      'auto'      : true
    25    });
    26 });
    27 </script>

    php:

    if ( !empty($_FILES) )
                {
                    $config['upload_path'] = $temp_path;
                    $config['allowed_types'] = '*';
                    $config['max_size'] = 4000;
                    $config['encrypt_name'] = true;
    
                    $this->load->library('upload', $config);
                    $this->upload->initialize($config);
    
                    if( ! ($this->upload->do_upload("Filedata"))) 
                    {
                        //echo $this->upload->display_errors('<p>', '</p>');
                        echo "ERROR";
                    }
                    else 
                    {
                        $img = $this->upload->data();
    
                        if($img['image_width'] > 650)
                        {
                            $config['image_library'] = 'gd2';
                            $config['source_image'] = $img['full_path'];
                            $config['create_thumb'] = TRUE;
                            $config['maintain_ratio'] = TRUE;
                            $config['width'] = 650;
    
                            $this->load->library('image_lib', $config);
    
                            $this->image_lib->resize();
                        }
    
                        // Resize image    
                        $this->Product_model->resize_image($img['full_path'], $temp_path.'/crop_'.$img["raw_name"].$img["file_ext"], 160, 120);
                        $this->Product_model->resize_image($img['full_path'], $temp_path.'/crop_crop_'.$img["raw_name"].$img["file_ext"], 80, 60);
    
                        $imeSlike = $img["raw_name"].$img["file_ext"];
    
                        echo $imeSlike;
                    }
                }

    运行结果是:文件保存名是:768f32dd43cc1f90b79c83cceed57eb2.png     取到的url:%EF%BB%BF768f32dd43cc1f90b79c83cceed57eb2.png

    %EF%BB%BF是什么就不进行解释了,上解决方法。

    php:

    1  $json = array("name" => $imeSlike, "error" => 0);
    2     echo json_encode($json);

    js:

    1 'onComplete': function(event, ID, fileObj, response, data) {
    2         eval("var obj1="+response);
    3 
    4         if( obj1.error == 0 )
    5         {
    6             $('.image_container').html('<img src="<?=base_url()?>ads_images_temp/crop_'+obj1.name+'"></img>');
    7         }
    8      }
  • 相关阅读:
    96. Unique Binary Search Trees
    515. Find Largest Value in Each Tree Row
    网络中数据传输的过程
    ARP/RARP协议
    JAVA静态代码块的作用及执行顺序
    MySQL中大于等于小于等于的写法
    Mybatis常见面试题总结及答案
    安全框架Shiro和Spring Security比较
    Excel VBA 连接各种数据库(一) VBA连接MySQL数据库
    Servlet、Servlet容器等内容讲解
  • 原文地址:https://www.cnblogs.com/CodeMaker/p/3998576.html
Copyright © 2020-2023  润新知