Grafische interesse |
|
Ben bezig een uploadscriptje aan het maken. Nu heb ik al een deel van wat ik wil gevonden.
- Nu zouden er nog de volgende functies moeten bijkomen:
->autonummering zowel thums/images
->autoresize "waarden blijven behouden"
->linken met een database bijvoorbeeld voor gebruik bij een forum
->ondersteuning van jpg, gif, png, jpeg
De functie om te kiezen hoeveel afbeeldingen je wilt uploaden staat er al in.
<?php
$upload_directory = "images/thumbs"; // hier word de foto eerst geupload!
$save_dir = "images/"; // hier word de foto opgeslagen!
$max_uploads = "2"; // max uploads
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if ($_POST['files'])
{
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="100"><br />', $i);
}
printf('<input type="button" onclick="javascript: history.back(-1);" value="Cancel">');
printf('<input type="submit" value="Upload bestanden">');
printf('<input type="hidden" name="history_files" value="%s">', $_POST['files']);
printf('</form>');
}
else
{
printf('<h3>Resultaten:</h3>');
printf('Bestanden geupload naar: %s<br /><br />', $upload_directory);
printf('<table border="1">');
for ($i = 1; $i <= $_POST['history_files']; $i++)
{
$tmp_filename = $_FILES['file_'.$i]['tmp_name'];
$filename = $_FILES['file_'.$i]['name'];
if (move_uploaded_file($tmp_filename, $upload_directory.'/'.$filename))
{
$status = 'Verzonden...';
$up_file = $upload_directory.'/'.$filename;
$srcimage = imagecreatefromjpeg($up_file);
$width = imageSX($srcimage);
$height = imageSY($srcimage);
if($width <= 250 && $height <= 250){
$t_width=$width;
} else {
if ($height < $width){
$t_width = 650;
}
else {
$t_width = 400;
}
}
$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('Aantal upload velden: ');
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="Creëer velden">');
printf('</form>');
}
?>
<?php $upload_directory = "images/thumbs"; // hier word de foto eerst geupload! $save_dir = "images/"; // hier word de foto opgeslagen! $max_uploads = "2"; // max uploads if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_POST['files']) { 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="100"><br />', $i); } printf('<input type="button" onclick="javascript: history.back(-1);" value="Cancel">'); printf('<input type="submit" value="Upload bestanden">'); printf('<input type="hidden" name="history_files" value="%s">', $_POST['files']); } else { printf('<h3>Resultaten:</h3>'); printf('Bestanden geupload naar: %s<br /><br />', $upload_directory); for ($i = 1; $i <= $_POST['history_files']; $i++) { $tmp_filename = $_FILES['file_'.$i]['tmp_name']; $filename = $_FILES['file_'.$i]['name']; { $status = 'Verzonden...'; $up_file = $upload_directory.'/'.$filename; $srcimage = imagecreatefromjpeg($up_file); $width = imageSX($srcimage); $height = imageSY($srcimage); if($width <= 250 && $height <= 250){ $t_width=$width; } else { if ($height < $width){ $t_width = 650; } else { $t_width = 400; } } $newh1= $height / $width; $newh2= $newh1 * $t_width; $destimage = imagecreatetruecolor($t_width,$newh2); imagecopyresampled($destimage,$srcimage,0,0,0,0,$t_width,$newh2,$width,$height); ImageJPEG($destimage,'',100); $file=$save_dir.'/'.$filename; $handle = fopen($file, 'ab'); $delete=$upload_directory.'/'.$filename; <? } else { $status = 'Fout!'; } printf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>', $i, ($filename)? $filename:' ', $status); } } } else { printf('<form method="post" action="%s">', '?page=admin&link=upload'); printf('Aantal upload velden: '); printf('<select name="files">'); for ($i = 1; $i <= $max_uploads; $i++) { printf('<option value="%1$s">%1$s', $i); } printf('<input type="submit" value="Creëer velden">'); } ?>
|