0

How i can save all uploaded images as jpg using php. i have code php to upload images like this

 $upload_dir="../uploads/";
 $filename = $_FILES['pic1']['name'];    
 $tmp_name=$_FILES['pic1']['tmp_name'];
 $path=$upload_dir.$filename;
 move_uploaded_file($tmp_name, $path);

i am using

     $image_path=imagecreatefromjpeg($path); 
     `imagejpeg($image_path);`  

but not work!.

Mona alawfi
  • 97
  • 2
  • 11

1 Answers1

1

This won't work because you tell PHP to create image from jpeg format and your uploaded file is gif or png. You could use imagecreatefromstring() function:

$image_path = imagecreatefromstring(file_get_contents($path));
imagejpeg($image_path);
Jojo
  • 1,875
  • 3
  • 29
  • 29