Forum Moderators: coopster
<?php
if(isset($_POST['send']) && $_POST['send'] == "ok") {
$allowedTypes = array("image/jpeg", "image/pjpeg", "image/jpg");
$maxFileSize = 1030720;
$max_width = 1024;
$max_height = 7680;
$path = $_SERVER['DOCUMENT_ROOT'] . "/";
if($_FILES['img']['size']> 0) {
if (in_array($_FILES['img']['type'],$allowedTypes)) {
if ($_FILES['img']['size'] <= $maxFileSize) {
$size = getimagesize($_FILES['img']['tmp_name']);
if($size[0] < $max_width) {
if($size[ 1 ] < $max_height) {
$tid = date("His_dmy", time());
$new_w = 150;
$division = $size[0] / 100;
$new_h = $size[ 1 ] / $division;
$dst_img=ImageCreateTrueColor($new_w,$new_h); $src_img=ImageCreateFromJpeg($_FILES['img']['tmp_name']);
ImageSY($src_img);
$filename2 = "thumbs/" . $img=$tid.$_FILES['img']['name'];
ImageJpeg($dst_img, $filename2);
Imagegif($dst_img, $filename2);
Imagepng($dst_img, $filename2);
move_uploaded_file($_FILES['img']['tmp_name'], $path.$tid.$_FILES['img']['name']) or die("Desværre er der sket en fejl!");
echo "<a href='http://mysite.com/".$tid.$_FILES['img']['name']." '>check</a>";
//<I trimmed the above line as it was too long and confusing-jatar_k>
if(isset($_POST['tekst'])) {
echo $_POST['tekst'];
}
} else {
$fejl = "Billede ikke sat ind: Filen er for høj!";
}
} else {
$fejl = "Billede ikke sat ind: Filen er for bred!";
}
} else {
$fejl = "The file is too big!";
}
} else {
$fejl = "Wrong File! We only allow: .jpg at the moment!";
}
}
}
if(isset($fejl)) echo $fejl;
?>
Thats the code I have (Don't mind the comments not being in english)
And this is what I have written in html that you need to see:
<form name="form" enctype="multipart/form-data" method="post">
<input type="hidden" name="send" value="ok"><table align="center" width="74%" cellspacing="0" cellpadding="2" border="0">
<tr>
<td width="79" nowrap align="left"><b>The File:</b></td>
<td><input name="img" class="file" type="file"></td>
</tr>
<tr>
<td align="left"></td>
<td><input type="submit" class="knap" value="Upload"></td>
</tr>
</table>
OK, this is what I need, I need to be able to upload 5 not 1 image(s) at a time, and I have no idea how....
Also, if possible can you make it so that it displays the 1 upload "form" and then underneath it saying: Want to upload more then 1 pic at a time?
and if you click it, the page changes and shows a row of 5 "boxes" instead of 1.
Thank you for helping in advance.
(Oh and on another note, when I make thumbnails the image honestly look really ugly (squashed down?), is there any way to make the images better looking?)
[edited by: jatar_k at 4:22 pm (utc) on Oct. 11, 2005]
once that is done you need to adjust your script to accept multiple images
a foreach should do it
then after that you can split the for to be a single or multiple upload
get the form done first and just start spitting out the $_FILES to see what you get, that will help you understand how to loop through them.
try changing your form to accept multiple file uploads
that's the best place to start
at the top of your processing script I would put something like
echo '<p><pre>';
print_r($_FILES);
echo '</pre>';
die();
this will break your script so that it doesn't do weird things while you are adding the extra fields. This will also dump the $_FILES array and will help you see if you have added the other fields correctly.