codeigniter l4 file upload & image manipulation & language

20
Codeigniter Framework 4. File Upload & Image manipulation & Language Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Upload: mohammad-tahsin-al-shalabi

Post on 17-Jul-2015

191 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: CodeIgniter L4 file upload & image manipulation & language

Codeigniter Framework

4. File Upload & Image manipulation & Language

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Page 2: CodeIgniter L4 file upload & image manipulation & language

Agenda

• File upload.

• Image manipulation.

• Language.

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Page 3: CodeIgniter L4 file upload & image manipulation & language

File upload

• File Upload class.

• Upload Form.

• Upload controller function.

• Upload class functions.

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Page 4: CodeIgniter L4 file upload & image manipulation & language

File upload class

• You can set various preferences,

restricting the type and size of the files.

• Uploading a file involves the following

general process:

An upload form is displayed.

When the form is submitted the file is

validated to make sure it is allowed to

be uploaded based on the preferences

you set.Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Page 5: CodeIgniter L4 file upload & image manipulation & language

Upload form

• File uploads require a multipart form.

form_open_multipart('upload/do_upload');

<input type="file" name="userfile" size="20" />

<input type="submit" value="upload" />

form_close();

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Page 6: CodeIgniter L4 file upload & image manipulation & language

Upload controller function

function do_upload(){

$config['upload_path'] = './uploads/';

$config['allowed_types'] = 'gif|jpg|png';

$this->load->library('upload', $config);

if ( ! $this->upload->do_upload())

echo $this->upload->display_errors();

else echo $this->upload->data();

}Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Page 7: CodeIgniter L4 file upload & image manipulation & language

Upload class functions

• $config array to set your preferences.

• do_upload() Performs the upload based

on the preferences you've set.

• data() returns an array containing all of

the data related to the uploaded file.

• display_errors() retrieves any error

messages if the do_upload()

function returned false.

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Page 8: CodeIgniter L4 file upload & image manipulation & language

Live Test

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Let’s Try It

Live!

Page 9: CodeIgniter L4 file upload & image manipulation & language

Image manipulation

• Image class.

• Class initializing.

• Class functions.

• Ex: resize function.

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Page 10: CodeIgniter L4 file upload & image manipulation & language

Image class

class lets you perform the following actions:

• Image Resizing.

• Thumbnail Creation.

• Image Cropping.

• Image Rotating

• Image Watermarking.

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Page 11: CodeIgniter L4 file upload & image manipulation & language

class Initializing

• Image class is must initialize in your

controller using as following:

• $config : array to set preferences.

$this->load->library('image_lib‘,$config);

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Page 12: CodeIgniter L4 file upload & image manipulation & language

Class functions

$this->image_lib->resize()

$this->image_lib->crop()

$this->image_lib->rotate()

$this->image_lib->watermark()

$this->image_lib->clear()

$this->image_lib->display_errors()

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Page 13: CodeIgniter L4 file upload & image manipulation & language

Ex: resize function

$config['source_image']=‘./upload/mypic.jpg';

$config['new_image']='./thumbnail/newpic.jpg‘;

$config['create_thumb'] = TRUE;

$config['maintain_ratio'] = TRUE;

$config[‘hight'] = 75;

$config['width'] = 50;

$this->load->library('image_lib', $config);

$this->image_lib->resize();

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Page 14: CodeIgniter L4 file upload & image manipulation & language

Live Test

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Let’s Try It

Live!

Page 15: CodeIgniter L4 file upload & image manipulation & language

Language

• Language class.

• Create a language files.

• Loading and Fetching.

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Page 16: CodeIgniter L4 file upload & image manipulation & language

Language class

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

• Build web application with multi

language.

• The Language Class provides functions to

retrieve language files and lines of text by

language.

Page 17: CodeIgniter L4 file upload & image manipulation & language

Create language files

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

• Language files must be named with

_lang.php as the file extension.

• Your language files must store in

application/language directory.

• assign each line of text to $lang :

$lang['language_key'] = "message to be show";

Language files must be named with _lang.php as the file extension

Page 18: CodeIgniter L4 file upload & image manipulation & language

Loading & Fetching

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

• In order to fetch a line from a particular file

you must load the file first as following:

$this->lang->load('filename', 'language');

• Fetching a line of text :

$this->lang->line(‘language_key’);

Language files must be named with _lang.php as the file extension

Page 19: CodeIgniter L4 file upload & image manipulation & language

Live Test

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Let’s Try It

Live!

Page 20: CodeIgniter L4 file upload & image manipulation & language

THANK YOU

Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi

Questions?