usage :
<?php
$this->load->helper('my_file_upload_helper');
check_file_is_image($_FILES['input_type_field_name']['name']);
?>
filename : my_file_upload_helper.php
<?php
function check_file_is_image($fileName,$extendsion_array=''){
//you need to send $_FILES["fileToUpload"]["name"]
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
//set_flash_msg("Sorry, only JPG, JPEG, PNG & GIF files are allowed.","myred");
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
return false;
}return TRUE;
}
function check_file_size($fileName, $maxSize='2000'){
//you need to send $_FILES["fileToUpload"]["size"]
if ($_FILES["fileToUpload"]["size"] > $maxSize) {
//set_flash_msg("Sorry, your file is too large.","myred");
echo "Sorry, your file is too large.";
return false;
}return true;
}
function check_file_exists($target_file){
if (file_exists($target_file)) {
//set_flash_msg("Sorry, file already exists.","myred");
echo "Sorry, file already exists.";
return false;
}return true;
}
?>
<?php
$this->load->helper('my_file_upload_helper');
check_file_is_image($_FILES['input_type_field_name']['name']);
?>
filename : my_file_upload_helper.php
<?php
function check_file_is_image($fileName,$extendsion_array=''){
//you need to send $_FILES["fileToUpload"]["name"]
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
//set_flash_msg("Sorry, only JPG, JPEG, PNG & GIF files are allowed.","myred");
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
return false;
}return TRUE;
}
function check_file_size($fileName, $maxSize='2000'){
//you need to send $_FILES["fileToUpload"]["size"]
if ($_FILES["fileToUpload"]["size"] > $maxSize) {
//set_flash_msg("Sorry, your file is too large.","myred");
echo "Sorry, your file is too large.";
return false;
}return true;
}
function check_file_exists($target_file){
if (file_exists($target_file)) {
//set_flash_msg("Sorry, file already exists.","myred");
echo "Sorry, file already exists.";
return false;
}return true;
}
?>
0 comments:
Post a Comment