I have looked around for information about this but haven't been able to find what I am looking for.
I have a site where users are able to upload an image for display on their user profile.
However, what I want to do is be able to make every photo that is uploaded a jpg. I feel like forcing people to only upload JPG files isn't good, but if I am able to make all files JPG, then that would be great.
Here is my code for when a user uploads an image:
require('includes/config.php');
// Upload and Rename File
if (isset($_POST['submit']))
{
$filename = $_FILES["file"]["name"];
$file_basename = substr($filename, 0, strripos($filename, '.')); // get file extention
$file_ext = substr($filename, strripos($filename, '.')); // get file name
$filesize = $_FILES["file"]["size"];
$allowed_file_types = array('.jpg','.jpeg','.png','.gif');
if (in_array($file_ext,$allowed_file_types) && ($filesize < 2000000))
{
// Rename file
$newfilename = ($_SESSION['memberID']) . $file_ext;
if (file_exists("upload/" . $newfilename))
{
// file already exists error
echo "You have already uploaded this file.";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $newfilename);
echo "File uploaded successfully.";
}
}
elseif (empty($file_basename))
{
// file selection error
echo "Please select a file to upload.";
}
elseif ($filesize > 200000)
{
// file size error
echo "The file you are trying to upload is too large.";
}
else
{
// file type error
echo "Only these file typs are allowed for upload: " . implode(', ',$allowed_file_types);
unlink($_FILES["file"]["tmp_name"]);
}
If anyone is able to suggest a way of changing uploaded files to JPG then please let me know.