Reputation: 555
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..
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;
}
Upvotes: 0
Views: 273
Reputation: 29462
$ext
will be jpg
or jpeg
, and you are checking for .jpg
or .jpeg
in your switch
statement, so for these files this will move to default case and do nothing.
Upvotes: 2