Hoe zorg ik dat er in dit script naast jpg ook gif en png geresized worden?
<?php
$upload_directory = "pictures"; // hier word de foto eerst geupload!
$save_dir = "files"; // hier word de foto opgeslagen!
$max_uploads = "2"; // max uploads
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if ($_POST['files'])
{ if (empty($username)) {echo "<script>alert('Je hebt je username niet ingevuld.'); document.location.href=('index2.html')</script>";}
printf('<form method="post" action="%s" enctype="multipart/form-data">', '?page=admin&link=upload');
for ($i = 1; $i <= $_POST['files']; $i++)
{
printf('       <input type="file" name="file_%s" size="50"><br />', $i);
}
printf('       <input type="button" onclick="javascript: history.back(-1);" value="Terug">');
printf('<input type="submit" value="Upload bestand(en)">');
printf("<input type=\"hidden\" name=\"username2\" value='$username'>");
printf('<input type="hidden" name="history_files" value="%s">', $_POST['files']);
printf('</form>');
}
else
{
printf('<h3>       Resultaten:</h3>');
printf('<table border="1">');
for ($i = 1; $i <= $_POST['history_files']; $i++)
{
$username = $_POST['username'];
$tmp_filename = $_FILES['file_'.$i]['tmp_name'];
$filename = $_POST['username2']."-".$_FILES['file_'.$i]['name'];
if (move_uploaded_file($tmp_filename, $upload_directory.'/'.$filename))
{
$status = '<a href="\files/foto_album.php"\>Verzonden...Bekijk de foto\'s</a>';
$up_file = $upload_directory.'/'.$filename;
$srcimage = imagecreatefromjpeg($up_file);
$width = imageSX($srcimage);
$height = imageSY($srcimage);
if($width <= 640 && $height <= 480){
$t_width=$width;
} else {
if ($height < $width){
$t_width = 640;
}
else {
$t_width = 480;
}
}
$newh1= $height / $width;
$newh2= $newh1 * $t_width;
$destimage = imagecreatetruecolor($t_width,$newh2);
imagecopyresampled($destimage,$srcimage,0,0,0,0,$t_width,$newh2,$width,$height);
ob_start();
ImageJPEG($destimage,'',100);
$buffer = ob_get_contents();
ob_end_clean();
$file=$save_dir.'/'.$filename;
$handle = fopen($file, 'ab');
fwrite($handle, $buffer);
fclose($handle);
$delete=$upload_directory.'/'.$filename;
@unlink($delete);?>
<?
}
else
{
$status = 'Fout!';
}
printf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>', $i, ($filename)?$filename:' ', $status);
}
printf('</table>');
}
}
else
{
printf('<form method="post" action="%s">', '?page=admin&link=upload');
printf('       <font color=\"red\" size=\"10\"><b>Hier uploaden</b><br><br></font>');
printf('       Username:<input type="text" name="username">');
printf('       Aantal upload\'s: ');
printf('<select name="files">');
for ($i = 1; $i <= $max_uploads; $i++)
{
printf('<option value="%1$s">%1$s', $i);
}
printf('</select> ');
printf('<input type="submit" value="Verder">');
printf('</form>');
}
?>
Ik dacht dat ik eerst moest controleren op het type(hoe doe ik dat?) en dan...?
1.119 views