【问题标题】:PHP - jpg/gif to pngPHP - jpg/gif转png
【发布时间】:2012-12-21 13:07:20
【问题描述】:

我在摆弄 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;
   }

【问题讨论】:

    标签: php image png gif jpeg


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-01-24
      • 2012-01-22
      • 2012-01-25
      • 1970-01-01
      • 1970-01-01
      • 2011-05-11
      • 2012-09-15
      • 1970-01-01
      • 2014-05-31
      相关资源
      最近更新 更多