B. Library E-mail
Berikut adalah contoh setting e-mail :
$this->load->library(“email”);
C.Library Uploading File
Adalah library untuk upload file ke server dan di simpan di folder tertentu. Folder tempat penyimpanan file di buat write accessible. Ukuran max di php.ini juga di atur agar sesuai dengan yang kita inginkan. Perhatikan baris berikut pada php.
file_uploads=on // Buat menjadi on
post_max_size = 2M // Edit ukuran file nya sesuai dengan yang anda inginkan.
upload_tmp_dir=”/opt/lampp/htdocs” // Folder ini harus write accssible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Kita perlu meload library e-mail di dalam controller atau di taruh di autoload.php | |
$this->email->from(“m.ikhwan@skill.co.id”,”M Ikhwan”); | |
$this->email->to(“m.ikhwan@skill.co.id”); | |
$this->email->cc(“el.ikhwan@ymail.com”); | |
$this->email->bcc(“el.ikhwan1@gmail.com”); | |
$this->email->subject(“Test Email”); | |
$this->email->message(“Hallo apa kabar nich … ?”); | |
$this->email->send(); | |
Setting E-mail : | |
Setting e-mail di set secara default di dalam file config.php. | |
Kita dapat melakukan setting manual seperti contoh di bawah ini : | |
$config[“protocol”]=”sendmail”; | |
$config[“mailpath”]=”/usr/sbin/sendmail”; | |
$config[“charset”]=”iso-8859-1”; | |
$config[“wordwrap”]=TRUE; | |
$this->email->initialize($config); |
Setting upload nya adalah sbb :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$config['upload_path']='./uploads/'; // Folder penyimpanan file. Musti Write accessible $config['allowed_types']='gif|jpg|png'; | |
$config['max_size']='100'; | |
$config['max_width']='1024'; | |
$config['max_height']='768'; | |
$this->load->library('upload',$config); | |
// Jika kita meletakkan library uploading file di dalam file autoload.php, maka syntax di bawah ini yang perlu kita taruh : | |
$this->upload->initialize($config); | |
$this->upload->do_upload() | |
Fungsi : Untuk melakukan eksekusi uploading file | |
Contoh : | |
<?php | |
class Upload extends Controller { | |
function Upload() | |
{ | |
parent::Controller(); | |
$this->load->helper(array('form', 'url')); | |
} | |
function index() | |
{ | |
$this->load->view('upload_form', array('error' => ' ' )); | |
} | |
function do_upload() | |
{ | |
$config['upload_path'] = './uploads/'; | |
$config['allowed_types'] = 'gif|jpg|png'; | |
$config['max_size'] = '100'; | |
$config['max_width'] = '1024'; | |
$config['max_height'] = '768'; | |
$this->load->library('upload', $config); | |
if ( ! $this->upload->do_upload()) | |
{ | |
$error = array('error' => $this->upload->display_errors()); $this->load->view('upload_form', $error); | |
} | |
else | |
{ | |
$data = array('upload_data' => $this->upload->data()); $this->load->view('upload_success', $data); | |
} | |
} | |
} | |
?> |
Agar form dapat melakukan uploading file, maka tipe enctype suatu form haruslah berbentuk multipart/form-data.
<form method=”post” enctype=”multipart/form-data”>
0 komentar