dongzuo7166 2013-12-18 07:13
浏览 17

多个图像在上载时调整大小并重命名

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.

  • 写回答

3条回答 默认 最新

  • dpklt4291 2013-12-18 07:16
    关注

    The error message said "Cannot redeclare createthumb()" because the function createthumb declaration is located inside a while loop. Could you please move it outside the loop?

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)