I'm calling do_upload_img() function only if there is any input value, like this:
function xxx()
{
if($_FILES['portfolioimg']['size'])
{
$portfolioimg = $this->do_upload_img();
}
// remaining code.......
}
do_upload_img() function
function do_upload_img()
{
if(isset($_FILES['portfolioimg']['size']) != 0){
$name_array = array();
$files = $_FILES;
$cpt = count($_FILES['portfolioimg']['name']);
$config['wm_type'] = 'overlay';
$config['wm_overlay_path'] = './assets/img/watermark.png';
$config['quality'] = 50;
$config['wm_vrt_alignment'] = 'middle';
$config['wm_hor_alignment'] = 'center';
for($i=0; $i<=$cpt-1; $i++)
{
$_FILES['userfile']['name']= $files['portfolioimg']['name'][$i];
$_FILES['userfile']['type']= $files['portfolioimg']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['portfolioimg']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['portfolioimg']['error'][$i];
$_FILES['userfile']['size']= $files['portfolioimg']['size'][$i];
$imgnam = rand(10,1000000);
$ext = pathinfo($files['portfolioimg']['name'][$i], PATHINFO_EXTENSION);
if($this->upload->initialize($this->set_upload_options($imgnam))){
$data = $this->upload->do_upload();
$config['source_image'] = './assets/portfolio_img/' . 'Soooo_'.$imgnam.'.'.$ext;
$this->image_lib->initialize($config);
$this->image_lib->watermark();
$name_array[] = $this->upload->data('file_name');
} else {
$this->session->set_flashdata('falsemsg','Only jpg, jpeg, png files are allowed to be uploaded.');
}
}
return $name_array;
}else{
return false;
}
}
View
<input class="fileUpload" accept="image/jpeg, image/jpg, image/png, image/gif" name="portfolioimg[]" type="file" value="" data-msg-accept="Please upload only jpg, jpeg, png and gif file">
If I run this xxx() function and if the portfolioimg
input field have no value then it showing a warning message like this:
A PHP Error was encountered
Severity: Warning
Message: imagecopy() expects parameter 1 to be resource, boolean
given
Filename: libraries/Image_lib.php
Line Number: 1217
And also if I use error_reporting(0), still the warning is displaying.