Hoi, hoe kan ik het onderstaande script geschikt maken voor .gif? Of heeft iemand een alternatief script (de mogelijkheid om zelf de naam te bepalen hetgeen je upload moet er in zitten!) Alvast bedankt
<?php
//Variables
$max = 180; //The width or height of the destination image
$dir = "../plaatjes/"; //The folder for the destionation image
$quality = 75; //The quality of the destination image
//Form to upload the pictures
if(!$upload)
{
echo("With this form you can upload your banner/image. The image has to be .jpg (temporarily not .gif!).<br />");
echo("Depending on the size, uploading your file can take a while. Please press the upload button only once!<br /><br />");
echo("<table>");
echo("<form action=\"picturesphp.php\" method=\"post\" enctype=\"multipart/form-data\">");
echo("<tr><td>File:</td><td><input type=\"file\" name=\"bestand\" /></td></tr>");
echo("<tr><td>File name (Your company name)</td><td><input type=\"text\" name=\"naam\" /></td><tr>");
echo("<tr><td></td><td><input type=\"submit\" name=\"upload\" value=\"upload\" ><input type=\"button\" value=\"Go back to form\" onClick=\"history.go(-1)\" ></td><tr></form></table>");
}
else
{
//Check if a file was selected
if(!$bestand)
{
echo("You did not select a file, please go back and select a file");
}
elseif(strlen($naam)==0)
{
echo("No file name, please go back and name your file");
}
//Check if the file-type is JPG
elseif(($_FILES['bestand']['type'] != "image/jpeg") && ($_FILES['bestand']['type'] != "image/pjpeg"))
{
echo("You can only upload .jpg" );
echo($_FILES['bestand']['type']);
}
else
{
$temp_file = $_FILES['bestand']['tmp_name'];
$source = imagecreatefromjpeg($temp_file);
//retrieving the width and height of the file
$width = imageSX($source);
$height = imageSY($source);
//determining the ratio to calculate the new height
//calculating the new height
if($widht < $max && $height < $max)
{
$new_width = $width;
$new_height = $height;
}
else
{
if($width > $height)
{
$ratio = $width/$height;
$new_width = $max;
$new_height = $new_width/$ratio;
}
elseif($width < $height)
{
$ratio = $height/$width;
$new_height = $max;
$new_width = $new_height/$ratio;
}
else
{
$new_height = $max;
$new_width = $max;
}
}
//Create a new true color image with the new width and height
$destination = imagecreatetruecolor($new_width, $new_height) or die("Can't process picture");
//Copy and resize the existing file to the dimensions of the new file
imagecopyresampled($destination, $source, 0,0,0,0,$new_width, $new_height, $width, $height);
//writing the new file
ob_start();
ImageJPEG($destination, '', $quality);
$buffer = ob_get_contents();
ob_end_clean();
$filename = $dir.$naam.'.jpg';
if(is_file($filename))
{
if(!unlink($filename))
{
echo("File could not be removed");
}
}
$handle = fopen($filename, 'ab'); //write only in binair
if(fwrite($handle, $buffer))
{
echo("File has been uploaded succesfully<br /><br />");
echo("<tr><td></td><td><input type=\"button\" value=\"Go back to form\" onClick=\"history.go(-2)\" ></td></tr></form></table>");
}
else
{
echo("An error occured during uploading your file, please try again");
}
fclose($handle);
}
}
?>
820 views