PHP - jpg/gif to png


PHP - jpg/gif to png

我在摆弄PHP,我已经在这里这么长时间了,我真的不知道我在这里做错了什么。

谁能帮助我,告诉我为什么转换后的图像不保存,而上传的文件保存得很好(而且,顺便说一句,不被删除)?

  $destination_path = getcwd().DIRECTORY_SEPARATOR."img".DIRECTORY_SEPARATOR."blog".DIRECTORY_SEPARATOR."uploads".DIRECTORY_SEPARATOR;
    $result = 0;
    $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION); 
    $target_path = $destination_path . $this->input->post("postId") . ".";
    if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path . $ext)) {
        switch ($ext) {
            case ".jpg": case ".jpeg":
                $image = imagecreatefromjpeg($target_path . $ext);
                imagepng($image, $target_path . "png");
                imagedestroy($image);
                break;
            case "gif":
                $image = imagecreatefromgif($target_path . $ext);
                imagepng($image, $target_path . "png");
                imagedestroy($image);
                break;
            default:
            break;
        }
        $result = 1;
   }

$ext将是jpgjpeg,并且您在switch语句中检查.jpg.jpeg,因此对于这些文件,这将移动到默认情况下,什么也不做。