I have a simple PHP file upload script:
$path = "uploads/";
$actual_image_name = time().$session_id.".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
move_uploaded_file($tmp, $path.$actual_image_name);
How can I save the uploaded image in JPG format?
There are a number of reasons why you might not be able to save a JPEG in Photoshop. The most common reason is that the file format is not supported. If you're using an older version of Photoshop, it may not support the JPEG file format. Another possibility is that the file has been corrupted or damaged.
First, open File Explorer and right-click on the folder you want to change the default picture. And choose Properties from the context menu. Then click the Customize tab and click the “Choose File” button. For example, here I am changing the default photo for the folder named “Saved pictures.”
JPEGs Lose Quality Every Time They're Opened: False Simply opening or displaying a JPEG image doesn't harm it in any way. Saving an image repeatedly during the same editing session without ever closing the image will not accumulate a loss in quality.
Try this:
<?php
$path = "uploads/";
$img = $_FILES['photoimg']['tmp_name'];
$dst = $path . $_FILES['photoimg']['name'];
if (($img_info = getimagesize($img)) === FALSE)
die("Image not found or not an image");
$width = $img_info[0];
$height = $img_info[1];
switch ($img_info[2]) {
case IMAGETYPE_GIF : $src = imagecreatefromgif($img); break;
case IMAGETYPE_JPEG : $src = imagecreatefromjpeg($img); break;
case IMAGETYPE_PNG : $src = imagecreatefrompng($img); break;
default : die("Unknown filetype");
}
$tmp = imagecreatetruecolor($width, $height);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $width, $height, $width, $height);
imagejpeg($tmp, $dst.".jpg");
?>
Make sure GD Library is installed and use it to convert gif or png to jpg like
if ($_FILES["photoimg"]["type"] == "image/jpeg" || $_FILES["photoimg"]["type"] == "image/png" || $_FILES["photoimg"]["type"] == "image/gif" )
{
if ($_FILES["photoimg"]["type"] == "image/png" || $_FILES["photoimg"]["type"] == "image/gif" )
{
imagejpeg(imagecreatefromstring(file_get_contents($_FILES["photoimg"]["tmp_name"])), "converted.jpg");
$actual_image_name = time().$session_id.".".$ext;
move_uploaded_file("converted.jpg", $path.$actual_image_name);
}
else
{
$actual_image_name = time().$session_id.".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
move_uploaded_file($tmp, $path.$actual_image_name);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With