Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Plain Text by registered user ajie ( 13 years ago )
<?php

/* controller */
class Tester extends CI_Controller {

function __construct()    {
 parent::__construct();
 $this->load->helper(array('form', 'url'));
 }

function index()    {
 $this->load->view('upload_form', array('error' => ' ' ));
 }
  
   
function cobaupload(){
 //$config['base_url'] = 'http://' . $_SERVER['HTTP_HOST'] . '/tutorial-ci-image-uploader';
// buat folder userfile sejajar dengan folder application dan system
 $config['upload_path'] = './asset/foto_testimonial/';    //pastikan permissionnya udah diset ke 777
 $config['allowed_types'] = 'gif|jpg|png|jpeg';    //tipe file yang diperbolehkan
 $config['max_width'] = 1028;    //ukuran maksimal yang diperbolehkan
 $config['max_height'] = 780;    //ukuran maksimal yang diperbolehkan
 $this->load->library('upload', $config);
 if($this->upload->do_upload('myfile')){//jika file berhasil diupload
 $tp=$this->upload->data();
 $acak = random_string(0); 
 
 
 $res = $tp['full_path'];
 //$ori = $tp['file_name'];
 
 $rw = $tp['raw_name'];
 $fr = $tp['file_ext'];
 

 $ori = $tp['raw_name'].$acak.$tp['file_ext'];
 
 $kcl = $tp['raw_name'].'_thumb'.$tp['file_ext'];
 $tnd = $acak.$tp['raw_name'].'_water'.$tp['file_ext'];
 $mr = $tp['file_path'].$ori;
 $tn = $tp['file_path'].$tnd;

 $ubah = $this->ubah_ukuran_gambar($res);
 $mark = $this->watermarking($mr);
 chmod($res,0777);
 chmod($tn,0777);
 $data = array('upload_data' => $this->upload->data(),'ori'=>$ori,'tnd'=>$tnd,'kcl'=>$kcl);
 $this->load->view('upload_success', $data);
 }
 else {//jika gagal
 $error = array('error' => $this->upload->display_errors());
 $this->load->view('upload_form', $error);
 }

}



 
 
 function random_string($mode)  
   {  
     $character_set_array = array( );  
     $character_set_array[ ] = array( 'count' => 6, 'characters' => 'abcdefghijklmnopqrstuvwxyz' );  
     $character_set_array[ ] = array( 'count' => 1, 'characters' => '0123456789' );  
     //jika password  
  if($mode==1)$character_set_array[ ] = array( 'count' => 1, 'characters' => '!@#$+-*&?:' );  
     $temp_array = array( );  
     foreach ( $character_set_array as $character_set )  
     {  
       for ( $i = 0; $i < $character_set[ 'count' ]; $i++ )  
       {  
         $temp_array[ ] = $character_set[ 'characters' ][ rand( 0, strlen( $character_set[ 'characters' ] ) - 1 ) ];  
       }  
     }  
     shuffle( $temp_array );  
     return implode( '', $temp_array );  
   }  
   
 }


/* view */


<html>
 <head>
 <title>Upload Form</title>
 </head>
 <body>
 <?php echo $error;?>
 <?php
 //jangan lupa menyertakan $this->load->helper('form'); di controller yang memanggil view ini
 echo form_open_multipart('tester/coba_upload', '');?>
 <div >
 <h2>upload, resize & watermarking</h2>
 <?php
 echo form_upload('myfile').
 form_submit('submit', 'Submit').'</p>';
 ?>
 </form>


 
 </div>
 </body>
 </html>

 

Revise this Paste

Parent: 62564
Your Name: Code Language: