plz help with multiple upload(newbie)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
piyashrija
Forum Newbie
Posts: 6
Joined: Sun Aug 16, 2009 8:44 pm

plz help with multiple upload(newbie)

Post by piyashrija »

i have been learning php from couple month earlier.
i cant figure out error going on with this code
i have error
Notice: Undefined index: file in C:\wamp\www\multiple_upload\multiple_upload1.php on line 11

please please help i have working with it from last 24 hr

Code: Select all

html>
<body>
<form name="form" action="multiple_upload1.php" enctype="multipart/form-data" method="post">
<p>Enter number of the uploads </p>
<p><input type="text" name="uploadneed" id="uploadneed" maxlength="1" ></p><br/>
<input type="submit" name="Submit" value="Submit" >
</form>
</body>
</html>
multiple_upload1.php here is error going on

Code: Select all

<html>
 
<body>
<form  name="form1" method="post" action="multiple_upload2.php" enctype="multipart/form-data">
<?php
$uploadnumber=$_POST['uploadneed'];
for($x=0;$x<$uploadnumber;$x++)
{?>
 
    <input name="uploadFile <?php echo $x;?>" type="file" id="uploadFile <?php echo $x;?>" />
 <?php  echo 'Upload:'.$_FILES['uploadFile'.$x]['name'];//[color=#40FF80]here is error[/color]
 
}
?>  
 
<input type="hidden" name="uploadnumber" value="<?php echo $uploadnumber; ?>" />
<input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>
multiple_uplaod2.php (just for testing)

Code: Select all

<?php
$uploadnumber=$_POST['uploadnumber'];
echo $uploadnumber;
for($x=0;$x<$uploadnumber;$x++)
{
    $file_name=$_FILES['uploadFile'.$x]['name'];
    
    echo $file_name;
 
}
?>
thanking you in advance
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: plz help with multiple upload(newbie)

Post by aceconcepts »

What is the first form supposed to do?
piyashrija
Forum Newbie
Posts: 6
Joined: Sun Aug 16, 2009 8:44 pm

Re: plz help with multiple upload(newbie)

Post by piyashrija »

first form is just supposed to take total number of upload file
cann't upload more than 9 file
total number is passed to next form
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: plz help with multiple upload(newbie)

Post by jackpf »

That sounds pointless. Why not process both in the same script?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: plz help with multiple upload(newbie)

Post by aceconcepts »

In the below code:

Code: Select all

<input name="uploadFile <?php echo $x;?>" type="file" id="uploadFile <?php echo $x;?>" />
 <?php  echo 'Upload:'.$_FILES['uploadFile'.$x]['name'];//here is error
 
$_FIELS['uploadFile...'] is not yet set so this is probably the error.

What you are also going to want to change is the name part of the file type element. Change it so that it can be posted as an array by using square brackets:

name="uploadeFile[]"
piyashrija
Forum Newbie
Posts: 6
Joined: Sun Aug 16, 2009 8:44 pm

Re: plz help with multiple upload(newbie)

Post by piyashrija »

thanks for reply
i tried with array but its not working
its again same error
pls help
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: plz help with multiple upload(newbie)

Post by susrisha »

Code: Select all

 
for($x=0;$x<$uploadnumber;$x++)
{?>
 
    <input name="uploadFile <?php echo $x;?>" type="file" id="uploadFile <?php echo $x;?>" />
 <?php  echo 'Upload:'.$_FILES['uploadFile'.$x]['name'];//here is error //i beleive u wouldnt need this line. 
           //try to remove this line and execute the code. There is no point in echoing uploaded file names
// when u didnt have any files that are uploaded in this file.
 
}
?> 
 
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: plz help with multiple upload(newbie)

Post by aceconcepts »

What do you do to process the data when you use the array approach []?
piyashrija
Forum Newbie
Posts: 6
Joined: Sun Aug 16, 2009 8:44 pm

Re: plz help with multiple upload(newbie)

Post by piyashrija »

thanks for reply susisra
while i have remove the line but when u move to multiple_upload2.php
u again have same problem i.e
Notice: Undefined index: uploadFile0 in C:\wamp\www\multiple_upload\multiple_upload2.php on line 6

Code: Select all

<?php
$uploadnumber=$_POST['uploadnumber'];
echo $uploadnumber;
for($x=0;$x<$uploadnumber;$x++)
{
   $file_name=$_FILES['uploadFile'.$x]['name'];
    
    echo $file_name;
 
}
?>
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: plz help with multiple upload(newbie)

Post by susrisha »

let me put the same code in my system and will get back to u with something..
piyashrija
Forum Newbie
Posts: 6
Joined: Sun Aug 16, 2009 8:44 pm

Re: plz help with multiple upload(newbie)

Post by piyashrija »

hi mark
i did this for array

Code: Select all

<input name="<?php $uploadFile[$x];?>" type="file" id="<?php $uploadFile[$x];?>"  />
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: plz help with multiple upload(newbie)

Post by susrisha »

Bingo.. Got it..

In the file multiple_upload1.php, u have a space which was eating away everything

Code: Select all

 
for($x=0;$x<$uploadnumber;$x++)
{?>
 
    <input name="uploadFile<?php echo $x;?>" type="file" id="uploadFile<?php echo $x;?>" />
//u left a space after uploadFile and the php echo statement. Thats what created the whole problem.
 
 <?php 
}
?>
 
piyashrija
Forum Newbie
Posts: 6
Joined: Sun Aug 16, 2009 8:44 pm

Re: plz help with multiple upload(newbie)

Post by piyashrija »

thank you all for the support
thats the mistake i never though of
thank you once again
Post Reply