By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,407 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

upload multiple files----still waiting for your reply

P: 114
Dear Friends,

I have post this query 4 days ago......but no one replied me.....

I request you all to please help me on this..............

I am trying to upload multiple files. But I can't find why it is not working fine. Here is the code.........


[HTML]<form method="POST" action="fileupload.php">
<p align="center">
<font face="Verdana" size="2">Number of files</font>
<input type="text" class="text" name="numfiles" size="3" maxlength="3"><br>
<input type="submit" value="Submit" name="submit" style="font-family: Verdana; font-size: 8pt; font-weight: bold; border: 1px solid #666666; padding: 2"></p>


$numoffile = $_POST['numfiles']; //value taking from numfile.php

$file_dir = "files/";

if ($_POST) {
for ($i=0;$i<$numoffile;$i++) {
if (trim($_FILES['myfiles']['name'][$i])!="") {
$newfile = $file_dir.$_FILES['myfiles']['name'][$i];
move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile);
if (isset($j)&&$j>0) print "<center><font family='verdana' size='2' color='green'>Your file(s) has been uploaded.</font><br>";
print "<p><h3 style='font-family:verdana;color:green;text-align:center'>Upload Files</h3></p><form method='post' enctype='multipart/form-data'>";
for($i=0;$i<$numoffile;$i++) {

$num = $i+1;
print "<center><span style='font-family:verdana;font-size:10pt'>File $num </span> <input type='file' name='myfiles[]' size='30'><br>";
print "<p align='center'><input type='submit' name='action' value='Upload'></p>";
print "</form>"; [/PHP]

Please help me out where is the error.........

May 11 '07 #1
Share this Question
Share on Google+
3 Replies

Expert 5K+
P: 5,821
Erm... the error would be that there's no file input in your HTML, so nothing's getting uploaded.
May 11 '07 #2

Expert 100+
P: 1,584
Try this coding and if you can't understand what i have done here come back to the thread.

I have done some changes to these areas..

1. hidden field.
2. for loops
3. form action


$file_dir = "files/";

if ($_POST['action'])
$newfile = $file_dir.$_FILES['myfiles'.$x.'']['name'];

if (isset($j)&&$j>0)
print "<center><font family='verdana' size='2' color='green'>Your file(s) has been uploaded.</font><br>";

print '<p><h3 style="font-family:verdana;color:green;text-align:center">Upload Files</h3></p>
<form action="'.$PHP_SELF.'" method="post" enctype="multipart/form-data">';

$num = $i+1;

print '<center><span style="font-family:verdana;font-size:10pt">File $num </span>
<input type="file" name="myfiles'.$num.'" size="30"><br>';


print '<p align="center"><input type="hidden" name="numfiles" value="'.$numoffile.'"><input type="submit" name="action" value="Upload"></p>';

print "</form>";
May 11 '07 #3

Expert 100+
P: 1,584
oops i changed this line also.
[PHP]<input type="file" name="myfiles[]" size="30">[/PHP]
with this
[PHP]<input type="file" name="myfiles'.$num.'" size="30">[/PHP]
May 11 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.