自己遇到的问题想办法解决了,后来上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 }
时间: 2024-10-13 05:23:33