Forum Moderators: coopster

Message Too Old, No Replies

change script from single upload to multiple

         

Snickers

2:32 pm on Oct 11, 2005 (gmt 0)

10+ Year Member



<?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]

jatar_k

3:05 pm on Oct 11, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



first things first is to make a form with multipl input fields

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.

Snickers

3:40 pm on Oct 11, 2005 (gmt 0)

10+ Year Member



I know your trying to help me, but the thing is, I haven't coded much of it, I got it from a friend which I don't speak to anymore..

I've only changed some settings and the html part of the design.

So I yield for help

jatar_k

4:28 pm on Oct 11, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you just need to do it in steps

start with making a form with multiple upload fields
move all of your testing to the top of your processing file and put them in a loop

once you get that to work than adding a second loop to the processing part should be easy enough

Snickers

4:55 pm on Oct 11, 2005 (gmt 0)

10+ Year Member



But I haven't done php in a long time, I've always just come up with the idea's and gotten people to do it...

I'm not very good at english either, having trouple understanding you :(

whoisgregg

10:45 pm on Oct 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This may be a perfect opportunity for you to polish up on your PHP skills then. If you are interested in learning and not just having someone else do it for you, we will help you -- you need only make the effort to apply the advice you receive and report back the results and relevant sections of new code.

Snickers

8:06 am on Oct 13, 2005 (gmt 0)

10+ Year Member



Ok, the thing is just that I wasn't planning on learning php, I have diffrent interests.

But ok, lets try, but lets start over since what you have said so far has only confused me.

jatar_k

4:02 pm on Oct 13, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well let's start with the html then

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.