I am trying to resize the image. It works fine with single image. But with multiple image, I have to use loop to get images one by one.
I am getting the error==> Fatal error: Cannot redeclare createthumb()
Below is my code for index
HTML
<input id="files" name="files[]" multiple="multiple" accept="image/*" type="file">
PHP
$count = count($_FILES['files']['name']);
$i = 0;
while($i<$count)
{
move_uploaded_file($_FILES["files"]["tmp_name"][$i],"uploaded_files/" . $_FILES["files"]["name"][$i]);
//===========>Image Resize<=============
function createthumb($name,$filename,$new_w,$new_h)
{
$system=explode(".",$name);
if (preg_match("/jpg|JPG|jpeg|JPEG/",$system[1])){$src_img=imagecreatefromjpeg($name);}
elseif (preg_match("/png|PNG/",$system[1])){$src_img=imagecreatefrompng($name);}
elseif (preg_match("/gif|GIF/",$system[1])){$src_img=imagecreatefromgif($name);}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
$thumb_w=500;
$thumb_h=300;
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if (preg_match("/png/",$system[1]))
{
imagepng($dst_img,$filename);
}
elseif (preg_match("/gif/",$system[1]))
{
imagegif($dst_img,$filename);
}
else{
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
$source_photo = 'uploaded_files/'. $_FILES["files"]["name"][$i];
$dest_photo = 'uploaded_files/'.$id.'_'.$i.'jpg';
//$d has some defined velue
$d = createthumb($source_photo, $dest_photo, 400, 400);
//===========>Image Resize<============
$i++;
}
It would be great if any one fix it.