groen29
Gebruiker
- Lid geworden
- 14 jan 2001
- Berichten
- 495
hallo
ik heb weer een vraagje ik heb een php script om foto's te uploaden (en het werkt
)
maar nu wil ik dat hij de foto's verkleind naar ongeveer 800x600.
maar de hoogte breete verhouding moet wel goed blijven.
snappen jullie wat ik bedoel
bram:thumb:
hier het script
<?
/*
Bugs: jort@myimages.nl
V1.1.1: 2004-07-13 1:26
Updates:
V1.1.1
Hij telde het aantal upload boxen niet goed, nu wel.
Website: http://www.myimages.nl
*/
//Instellingen
$forms = 1; //Standaard aantal file uploads
$user = TRUE; //User kan aangeven dat hij meer files wil uploaden
$max_size = 0; //Maximale bestands grootte, 0 voor ongelimiteerd
$max_thumb = 100; //Maximale hoogte dan wel breedte van de thumb.
$ext = "jpg jpeg gif png"; // Welke extensies kunnen er worden geupload ( als alles mag dan niks invullen )
//Script
// Toegestaande extensies opvragen
$ext = strtolower($ext);
$ext = explode(" ", $ext);
$aantal = count($ext);
if(isset($_POST['forms']) && $user==TRUE){
$forms=$_POST['forms'];
}
?>
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Upload img + thumb V1.0</title>
<a target="_self" href="http://groen29.gr.funpic.org/Fotocollectiemetthumbnails.php">
<font size="5">alle foto's bekijken</font></a></p>
</head>
<body>
<?
if($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['submit'])){
$aantal=count($_FILES['image']['type']);
$i=0;
for($i=0;$i<$aantal;$i++){
$foto_name=rand(1,9999)."_".time();
if(!empty($_FILES['image']['tmp_name'][$i])){
$type= $_FILES['image']['type'][$i];
// Bestands naam opvragen
$bestand2 = explode("\\", $_FILES['image']['name'][$i]);
$laatste = count($bestand2) - 1;
$bestand2 = "$bestand2[$laatste]";
// Extensie van bestand opvragen
$bestand3 = explode(".", $bestand2);
$laatste = count($bestand3) - 1;
$bestand3 = "$bestand3[$laatste]";
$bestand3 = strtolower($bestand3);
for ($tel = 0;$tel < $aantal; $tel++){
if ($bestand3 == $ext[$tel]){
$extfout = "nee";
}
}
if($type == "image/gif" OR $type == "image/pjpeg" OR $type == "image/x-png" OR $type == "image/jpeg"){
if(!empty($max_size) && $_FILES['image']['size'][$i] > $max_size){
echo"Bestand is te groot: ".$_FILES['image']['size'][$i]." / ".$max_size."<br>\n";
}elseif(!isset($extfout)){
}else{
if(move_uploaded_file($_FILES['image']['tmp_name'][$i], "./img/".$foto_name.".".$bestand3)){
echo $foto_name.".".$bestand3." is succesvol geupload.<br \>\n<img src=\"./img/".$foto_name.".".$bestand3."\" \><br \>\n";
?>
<html>
</head>
<p>
<a target="_self" href="http://groen29.gr.funpic.org/Plaatjesuploadthumbsfotosoppaginas.php">
<font size="5">nog een foto uploaden</font></a></p>
<p>
<a target="_self" href="http://groen29.gr.funpic.org/Fotocollectiemetthumbnails.php">
<font size="5">alle foto's bekijken</font></a></p>
</head>
<body>
<?
if($type == "image/gif"){
$photo = imagecreatefromgif("./img/".$foto_name.".".$bestand3);
}elseif($type == "image/pjpeg" OR $type == "image/jpeg"){
$photo = imagecreatefromjpeg ("./img/".$foto_name.".".$bestand3);
}elseif($type == "image/x-png"){
$photo = imagecreatefrompng("./img/".$foto_name.".".$bestand3);
}
$photo_dimensions_width = imagesx ($photo);
$photo_dimensions_height = imagesy ($photo);
if ($photo_dimensions_width > $max_thumb OR $photo_dimensoons_height > $max_thumb) {
if ($photo_dimensions_width == $photo_dimensions_height) {
$thumb_dimensions_width = $max_thumb;
$thumb_dimensions_height = $max_thumb;
}
elseif ($photo_dimensions_width > $photo_dimensions_height) {
$value = $photo_dimensions_width / $max_thumb;
$thumb_dimensions_width = $max_thumb;
$thumb_dimensions_height = round ($photo_dimensions_height / $value);
}
else {
$value = $photo_dimensions_height / $max_thumb;
$thumb_dimensions_height = $max_thumb;
$thumb_dimensions_width = round ($photo_dimensions_width / $value);
}
}
else {
$thumb_dimensions_width = $photo_dimensions_width;
$thumb_dimensions_height = $photo_dimensions_height;
}
$create_thumb = imagecreatetruecolor ($thumb_dimensions_width, $thumb_dimensions_height);
imagecopyresampled ($create_thumb, $photo, 0, 0, 0, 0, $thumb_dimensions_width, $thumb_dimensions_height, $photo_dimensions_width, $photo_dimensions_height);
ImageJpeg($create_thumb,'./img/thumb/'.$foto_name.".jpg",90);
Imagedestroy($photo);
echo"Thumb, ./img/thumb/".$foto_name.".jpg, is gemaakt.<br>\n<img src=\"./img/thumb/".$foto_name.".jpg\" \><br \>\n";
}else{
echo $_FILES['image']['name'][$i]." kon niet geupload worden.<br \>\n";
}
}
}else{
echo "Ongeldig type: ".$type."<br>\n";
}
}else{
echo "Geen file geselecteerd.<br>\n";
}
}
}else{
if($user==TRUE){
?>
<FORM NAME="select" METHOD="POST" action="<?echo$_SERVER['PHP_SELF'];?>">
Aantal: <SELECT name="forms" onchange="javascript:document.select.submit();">
<?
for($i=1;$i<21;$i++){
?>
<option value="<?=$i?>"><?=$i?></option>
<?
}
?>
</SELECT>
</FORM>
<?
}
?>
<FORM NAME="upload_form" METHOD="POST" ACTION="<?echo$_SERVER['PHP_SELF'];?>" ENCTYPE="multipart/form-data">
<?
for($i=0;$i<$forms;$i++){
?>
<INPUT TYPE="file" value="1" NAME="image[<?=$i?>]" \><br \>
<?
}
?>
<INPUT TYPE="submit" NAME="submit" VALUE="Upload">
</FORM>
<?
}
?>
</body>
</html>
ik heb weer een vraagje ik heb een php script om foto's te uploaden (en het werkt

maar nu wil ik dat hij de foto's verkleind naar ongeveer 800x600.
maar de hoogte breete verhouding moet wel goed blijven.
snappen jullie wat ik bedoel
bram:thumb:
hier het script
<?
/*
Bugs: jort@myimages.nl
V1.1.1: 2004-07-13 1:26
Updates:
V1.1.1
Hij telde het aantal upload boxen niet goed, nu wel.
Website: http://www.myimages.nl
*/
//Instellingen
$forms = 1; //Standaard aantal file uploads
$user = TRUE; //User kan aangeven dat hij meer files wil uploaden
$max_size = 0; //Maximale bestands grootte, 0 voor ongelimiteerd
$max_thumb = 100; //Maximale hoogte dan wel breedte van de thumb.
$ext = "jpg jpeg gif png"; // Welke extensies kunnen er worden geupload ( als alles mag dan niks invullen )
//Script
// Toegestaande extensies opvragen
$ext = strtolower($ext);
$ext = explode(" ", $ext);
$aantal = count($ext);
if(isset($_POST['forms']) && $user==TRUE){
$forms=$_POST['forms'];
}
?>
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Upload img + thumb V1.0</title>
<a target="_self" href="http://groen29.gr.funpic.org/Fotocollectiemetthumbnails.php">
<font size="5">alle foto's bekijken</font></a></p>
</head>
<body>
<?
if($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['submit'])){
$aantal=count($_FILES['image']['type']);
$i=0;
for($i=0;$i<$aantal;$i++){
$foto_name=rand(1,9999)."_".time();
if(!empty($_FILES['image']['tmp_name'][$i])){
$type= $_FILES['image']['type'][$i];
// Bestands naam opvragen
$bestand2 = explode("\\", $_FILES['image']['name'][$i]);
$laatste = count($bestand2) - 1;
$bestand2 = "$bestand2[$laatste]";
// Extensie van bestand opvragen
$bestand3 = explode(".", $bestand2);
$laatste = count($bestand3) - 1;
$bestand3 = "$bestand3[$laatste]";
$bestand3 = strtolower($bestand3);
for ($tel = 0;$tel < $aantal; $tel++){
if ($bestand3 == $ext[$tel]){
$extfout = "nee";
}
}
if($type == "image/gif" OR $type == "image/pjpeg" OR $type == "image/x-png" OR $type == "image/jpeg"){
if(!empty($max_size) && $_FILES['image']['size'][$i] > $max_size){
echo"Bestand is te groot: ".$_FILES['image']['size'][$i]." / ".$max_size."<br>\n";
}elseif(!isset($extfout)){
}else{
if(move_uploaded_file($_FILES['image']['tmp_name'][$i], "./img/".$foto_name.".".$bestand3)){
echo $foto_name.".".$bestand3." is succesvol geupload.<br \>\n<img src=\"./img/".$foto_name.".".$bestand3."\" \><br \>\n";
?>
<html>
</head>
<p>
<a target="_self" href="http://groen29.gr.funpic.org/Plaatjesuploadthumbsfotosoppaginas.php">
<font size="5">nog een foto uploaden</font></a></p>
<p>
<a target="_self" href="http://groen29.gr.funpic.org/Fotocollectiemetthumbnails.php">
<font size="5">alle foto's bekijken</font></a></p>
</head>
<body>
<?
if($type == "image/gif"){
$photo = imagecreatefromgif("./img/".$foto_name.".".$bestand3);
}elseif($type == "image/pjpeg" OR $type == "image/jpeg"){
$photo = imagecreatefromjpeg ("./img/".$foto_name.".".$bestand3);
}elseif($type == "image/x-png"){
$photo = imagecreatefrompng("./img/".$foto_name.".".$bestand3);
}
$photo_dimensions_width = imagesx ($photo);
$photo_dimensions_height = imagesy ($photo);
if ($photo_dimensions_width > $max_thumb OR $photo_dimensoons_height > $max_thumb) {
if ($photo_dimensions_width == $photo_dimensions_height) {
$thumb_dimensions_width = $max_thumb;
$thumb_dimensions_height = $max_thumb;
}
elseif ($photo_dimensions_width > $photo_dimensions_height) {
$value = $photo_dimensions_width / $max_thumb;
$thumb_dimensions_width = $max_thumb;
$thumb_dimensions_height = round ($photo_dimensions_height / $value);
}
else {
$value = $photo_dimensions_height / $max_thumb;
$thumb_dimensions_height = $max_thumb;
$thumb_dimensions_width = round ($photo_dimensions_width / $value);
}
}
else {
$thumb_dimensions_width = $photo_dimensions_width;
$thumb_dimensions_height = $photo_dimensions_height;
}
$create_thumb = imagecreatetruecolor ($thumb_dimensions_width, $thumb_dimensions_height);
imagecopyresampled ($create_thumb, $photo, 0, 0, 0, 0, $thumb_dimensions_width, $thumb_dimensions_height, $photo_dimensions_width, $photo_dimensions_height);
ImageJpeg($create_thumb,'./img/thumb/'.$foto_name.".jpg",90);
Imagedestroy($photo);
echo"Thumb, ./img/thumb/".$foto_name.".jpg, is gemaakt.<br>\n<img src=\"./img/thumb/".$foto_name.".jpg\" \><br \>\n";
}else{
echo $_FILES['image']['name'][$i]." kon niet geupload worden.<br \>\n";
}
}
}else{
echo "Ongeldig type: ".$type."<br>\n";
}
}else{
echo "Geen file geselecteerd.<br>\n";
}
}
}else{
if($user==TRUE){
?>
<FORM NAME="select" METHOD="POST" action="<?echo$_SERVER['PHP_SELF'];?>">
Aantal: <SELECT name="forms" onchange="javascript:document.select.submit();">
<?
for($i=1;$i<21;$i++){
?>
<option value="<?=$i?>"><?=$i?></option>
<?
}
?>
</SELECT>
</FORM>
<?
}
?>
<FORM NAME="upload_form" METHOD="POST" ACTION="<?echo$_SERVER['PHP_SELF'];?>" ENCTYPE="multipart/form-data">
<?
for($i=0;$i<$forms;$i++){
?>
<INPUT TYPE="file" value="1" NAME="image[<?=$i?>]" \><br \>
<?
}
?>
<INPUT TYPE="submit" NAME="submit" VALUE="Upload">
</FORM>
<?
}
?>
</body>
</html>