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);
}
}
?>
Ik bedoel dan: zowel .gif als .jpg kunnen uploaden.

Heb ik er niet helemaal duidelijk bij gezet. Alvast bedankt!
Hoe werkt dat dan met die twee php files? --> http://www.phphulp.nl/php/scripts/9/464/

Eentje om aan te roepen en nog een andere, waar moet ik die plaatsen? En kun je via dat script ook als uploader de naam opgeven hoe het bestand weggeschreven wordt?
Functie (Onderste script)
moet je includen in je bestand de andere is gewoon een voorbeeld hoe je het moet aan roepen.
en ik zou er ff een header bij pleuren op z'n minst header("content-type: image");, maar ik weet niet of dat mag zonder dat je defineerd welk specefiek type het is
Heej je kunt tog gewoon een .gif extensie invoeren bij de toegstane extensies?

Of heb ik dat nu verkeerd?
en niet dezelfde vraag 2x topic voor maken, niet netjes
ArendJan,

Dat laatst gaat niet lukken omdat er nog meer specifieke functies voor het aanpassen van het bestand zijn...

Jep dat was ook mijn probleem.. ik had er van gemaakt

//Check if the file-type is JPG or GIF
elseif(($_FILES['bestand']['type'] != "image/jpeg") && ($_FILES['bestand']['type'] != "image/pjpeg") &&
($_FILES['bestand']['type'] != "image/gif"))
{
echo("You can only upload .jpg or .gif" );
echo($_FILES['bestand']['type']);
}
else
{

Maar dan heb je nog niet genoeg veranderd, er moet nog iets worden veranderd in het wegschrijf gedeelte, maar daar kwam ik dus niet uit.

@ wes, sorry maar niemand reageerde op dat andere topic

Reageren