Jump to content

[SOLVED] Image Upload help please


jonnyw6969

Recommended Posts

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

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);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.