jonnyw6969 Posted April 29, 2008 Share Posted April 29, 2008 Hi all, Im trying to create a simple image upload for my site. I have the upload working fine and it saves the image to the correct location and also stores extra information in the database. The problem is I need all the images uploaded as jpg's but I want to be able to except gif and bmp images as well. Could someone help me with a script that would save all uploaded images as jpg's please. So far my code looks like this if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg"))) { move_uploaded_file($_FILES["file"]["tmp_name"], "../images/stock/".$artistname ."/" . $imagename); Link to comment https://forums.phpfreaks.com/topic/103374-solved-image-upload-help-please/ Share on other sites More sharing options...
jonnyw6969 Posted April 29, 2008 Author Share Posted April 29, 2008 Hi, Fixed it. Thought I'd share incase there is someone else like me needing help with this. $filename = $_FILES['file']['name']; $temporary_name = $_FILES['file']['tmp_name']; $mimetype = $_FILES['file']['type']; $filesize = $_FILES['file']['size']; switch($mimetype) { case "image/jpg": case "image/jpeg": case "image/pjpeg": //IE's weird jpeg MIME type $i = imagecreatefromjpeg($temporary_name); break; case "image/gif": $i = imagecreatefromgif($temporary_name); break; case "image/png": $i = imagecreatefrompng($temporary_name); break; } unlink($temporary_name); imagejpeg($i,"../images/stock/".$arname ."/" . $imagename,100); Link to comment https://forums.phpfreaks.com/topic/103374-solved-image-upload-help-please/#findComment-529415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.