Page 1 of 1

plz help with multiple upload(newbie)

Posted: Sun Aug 16, 2009 9:27 pm
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

Re: plz help with multiple upload(newbie)

Posted: Sun Aug 16, 2009 9:33 pm
by aceconcepts
What is the first form supposed to do?

Re: plz help with multiple upload(newbie)

Posted: Sun Aug 16, 2009 9:41 pm
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

Re: plz help with multiple upload(newbie)

Posted: Sun Aug 16, 2009 10:03 pm
by jackpf
That sounds pointless. Why not process both in the same script?

Re: plz help with multiple upload(newbie)

Posted: Sun Aug 16, 2009 10:05 pm
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[]"

Re: plz help with multiple upload(newbie)

Posted: Sun Aug 16, 2009 10:54 pm
by piyashrija
thanks for reply
i tried with array but its not working
its again same error
pls help

Re: plz help with multiple upload(newbie)

Posted: Sun Aug 16, 2009 11:02 pm
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.
 
}
?> 
 

Re: plz help with multiple upload(newbie)

Posted: Sun Aug 16, 2009 11:16 pm
by aceconcepts
What do you do to process the data when you use the array approach []?

Re: plz help with multiple upload(newbie)

Posted: Sun Aug 16, 2009 11:18 pm
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;
 
}
?>

Re: plz help with multiple upload(newbie)

Posted: Sun Aug 16, 2009 11:23 pm
by susrisha
let me put the same code in my system and will get back to u with something..

Re: plz help with multiple upload(newbie)

Posted: Sun Aug 16, 2009 11:30 pm
by piyashrija
hi mark
i did this for array

Code: Select all

<input name="<?php $uploadFile[$x];?>" type="file" id="<?php $uploadFile[$x];?>"  />

Re: plz help with multiple upload(newbie)

Posted: Sun Aug 16, 2009 11:33 pm
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 
}
?>
 

Re: plz help with multiple upload(newbie)

Posted: Mon Aug 17, 2009 12:02 am
by piyashrija
thank you all for the support
thats the mistake i never though of
thank you once again