upload

class untuk mengatur upload file

Cara pengggunaan:

$config = array(
	'max_size'       => 0,		// The maximum size (in kilobytes) that the file can be. Set to zero for no limit. Note: Most PHP installations have their own limit, as specified in the php.ini file. Usually 2 MB (or 2048 KB) by default.
	'max_width'      => 0,		// The maximum width (in pixels) that the image can be. Set to zero for no limit.
	'max_height'     => 0,		// The maximum height (in pixels) that the image can be. Set to zero for no limit.
	'max_filename'   => 0,		// The maximum length that a file name can be. Set to zero for no limit.
	'allowed_types'  => "",		// The mime types corresponding to the types of files you allow to be uploaded. Usually the file extension can be used as the mime type. Can be either an array or a pipe-separated string.
	'file_name'      => "",		// The extension provided in the file name must also be an allowed file type. If no extension is provided in the original file_name will be used.
	'file_type'      => "",		// File MIME type identifier
	'file_size'      => "",		// File size in kilobytes
	'file_ext'       => "",		// Filename extension, period included
	'upload_path'    => "", 	// $Bbc->mod['dir']||_ROOT.'images/uploads/' -- The path to the directory where the upload should be placed. The directory must be writable and the path must be absolute.
	'overwrite'      => FALSE,// TRUE/FALSE (boolean)	If set to true, if a file with the same name as the one you are uploading exists, it will be overwritten. If set to false, a number will be appended to the filename if another with the same name exists.
	'encrypt_name'   => FALSE,// TRUE/FALSE (boolean)	If set to TRUE the file name will be converted to a random encrypted string. This can be useful if you would like the file saved with a name that can not be discerned by the person uploading it.
	'is_image'       => FALSE,// Whether the file is an image or not. 1 = image. 0 = not.
	'image_width'    => '',		// Image width
	'image_height'   => '',		// Image height
	'image_type'     => '',		// Image type (usually the file name extension without the period)
	'remove_spaces'  => TRUE,	// TRUE/FALSE (boolean)	If set to TRUE, any spaces in the file name will be converted to underscores. This is recommended.
);
$obj = _class('upload', $config);
$obj->do_upload('thefile'); // $_FILES['thefile'] harus ada
$arr = $obj->data();
Script diatas menunjukan semua fitur-fitur apa saja yang tersedia dalam class upload ini, adapun penggunaan nya terkadang lebih simple karena kita hanya menggunakan sebagian fitur sesuai dengan yang kita butuhkan

Contoh penggunaan:

$config = array(
	'allowed_types'  => 'jpg|png|jpeg|pdf',
	'upload_path'    => _CACHE,
	'overwrite'      => FALSE,
	'encrypt_name'   => FALSE
);
$upload = _class('upload', $config);
$return = $upload->do_upload('thefile');
$data   = $upload->data();
$error  = $upload->display_errors();
pr(array(
	'data'   => $data,
	'return' => $return?'true':'false',
	'error'  => $error
	));
Contoh output dari script di atas
## JIKA ERROR ##
Array
(
		[data] => Array
				(
						[file_name] => config.json
						[file_type] => application/json
						[file_path] => /Users/me/Sites/test/images/cache/
						[full_path] => /Users/me/Sites/test/images/cache/config.json
						[raw_name] => config
						[orig_name] => 
						[file_ext] => .json
						[file_size] => 0.37
						[is_image] => 
						[image_width] => 
						[image_height] => 
						[image_type] => 
						[image_size_str] => 
				)
		[return] => false
		[error] => upload_invalid_filetype
)

## JIKA BERHASIL ##
Array
(
		[data] => Array
				(
						[file_name] => original1.jpg
						[file_type] => image/jpeg
						[file_path] => /Users/me/Sites/test/images/cache/
						[full_path] => /Users/me/Sites/test/images/cache/original1.jpg
						[raw_name] => original1
						[orig_name] => original.jpg
						[file_ext] => .jpg
						[file_size] => 263
						[is_image] => 1
						[image_width] => 1024
						[image_height] => 640
						[image_type] => jpeg
						[image_size_str] => width="1024" height="640"
				)
		[return] => true
		[error] => 
)

 

File Path: includes/class/upload.php class untuk mengatur upload file

0 Comment

Post Your Comment

Terakhir Dilihat

Method Tersedia