简体   繁体   English

PHP - jpg / gif到png

[英]PHP - jpg/gif to png

I am fiddeling with PHP and i've been at it for so long i really don't see what i'm doing wrong here.. 我迷上了PHP并且我已经使用了很长时间我真的没有看到我在这里做错了什么..

Can anyone help me out and tell me why the converted image is not saved, while the uploaded file gets saved just fine (and, btw, doesn't get deleted)? 任何人都可以帮助我,告诉我为什么转换后的图像没有保存,而上传的文件保存得很好(顺便说一下,不会被删除)?

  $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 ,因此对于这些文件,这将移至默认情况并且不执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM