I have some code and at the moment its only dealing with 1 mage, I need to add the option of uploading 3 other images at the same time. I could sort of duplicate what I got another 3 times, but wondered if there was a simpler way to do it.
html
<input type="file" name="image" id="image" />
php
$validExtensions = array('.jpg', '.jpeg', '.gif', '.png');
function fileWasUploaded($name)
{
if (!file_exists($_FILES[$name]['tmp_name']))
{
return false;
}
return is_uploaded_file($_FILES[$name]['tmp_name']);
}
$image = "no-image.jpg";
if (fileWasUploaded("image") === true)
{
$fileExtension = strrchr(strtolower($_FILES['image']['name']), ".");
if (!in_array($fileExtension, $validExtensions))
{
echo "Uploaded file was not an image";
}
else
{
$image = $_POST["url"] . ".jpg";
$destination = '../images/products/' . $image;
$thumbnail = '../images/products/thumbs/' . $image;
$manipulator = new ImageManipulator($_FILES['image']['tmp_name']);
$manipulator->save($destination);
$newWidth = 150;
$factor = $manipulator->getWidth() / $newWidth;
$manipulator->resample($newWidth, $manipulator->getHeight() / $factor, false);
$manipulator->save($thumbnail);
}
}
There an include that goes with it which is called imagemanipulator.php which by the looks is just changing the size of it before upload.