Forum Moderators: coopster

Message Too Old, No Replies

Simple Multiple file uploader

         

Phobia1

8:00 pm on Dec 6, 2008 (gmt 0)

10+ Year Member



Hi Guys
Greetings from Bulgaria.
I am trying to get a 5 file (always) uploader to work.
Have had some success but need some help.
As the loop runs the progressive file names are added to the first etc.
<form name="form1" enctype="multipart/form-data" method="post" action="upload3.php">
<p>
<?
$uploadsNeeded = 5;
for($i=0; $i < $uploadsNeeded; $i++){
?>
<input name="uploadFile<? echo $i;?>" type="file" id="uploadFile<? echo $i;?>" />
</p>
<? } ?>
<p><input name="uploadsNeeded" type="hidden" value="<? echo $uploadsNeeded;?>" />
<input type="submit" name="Submit" value="Submit" />
</p>
</form>

and upload3.php
<?
$target = "/home/areabulnet/public_html/uploads/";
for($i = 0; $i < 5; $i++){
$target = $target . basename( $_FILES['uploadFile'.$i]['name']) ;
echo $target;
$ok=1;

//This is our size condition
if ($uploaded_size > 1280000)
{
echo "Sorry Your file is too large.<br>";
$ok=0;
}

//This is our limit file type condition
if (isset($uploaded_type) && $uploaded_type =="text/jpg")
{
echo "Not an approved file type.";
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}

//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploadFile'.$i]['tmp_name'], $target))
{
echo "The file ". basename( $_FILES[’uploadFile’.$i][’name’]). " has been uploaded. ";

}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
}
?>

Thanks in advance for replies
regards
Fred

Phobia1

4:52 pm on Dec 7, 2008 (gmt 0)

10+ Year Member



I fixed the problem, silly me, initialisation again.
<?
$webtarget = "/home/website/public_html/uploads/";
for($i = 0; $i < 5; $i++){
$target = $webtarget . basename( $_FILES['uploadFile'.$i]['name']) ;

coopster

7:35 pm on Dec 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Different path you mean? That was the issue?

Greetings from Bulgaria.

Thanks, and greetings to you friend.

Phobia1

7:43 pm on Dec 8, 2008 (gmt 0)

10+ Year Member



no, the $target value just concatenated. By changing the first to $webtarget overcame the problem.
So where are you in Bulgaria... me V.T.

coopster

7:48 pm on Dec 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Oh, OK! Now I understand. I see it now.
I am not from Bulgaria, I was quoting your original message. And then greeting you back. Greetings from Wisconsin, USA :)

Phobia1

7:51 pm on Dec 8, 2008 (gmt 0)

10+ Year Member



haha
No problem. I had fun time getting the code 'upload to work' on the Linux server. FTP_connect etc not working, just ujaz.
Still in the snd was very simple.
Greetings from Veliko Turnovo, Bulgaria :-)