473,385 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

114 100+
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.........

numfile.php

[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>
<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>
</form>[/HTML]


fileupload.php

[PHP]
$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);
$j++;
}
}
}
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.........

Thanks
Deepak
May 11 '07 #1
3 2123
pbmods
5,821 Expert 4TB
Erm... the error would be that there's no file input in your HTML, so nothing's getting uploaded.

http://php.net/manual/en/features.fi...d.multiple.php
May 11 '07 #2
ak1dnar
1,584 Expert 1GB
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

[PHP]
<?php
$numoffile=$_POST['numfiles'];


$file_dir = "files/";

if ($_POST['action'])
{
for($x=1;$x<=$numoffile;$x++)
{
$newfile = $file_dir.$_FILES['myfiles'.$x.'']['name'];
move_uploaded_file($_FILES['myfiles'.$x.'']['tmp_name'],$newfile);
$j++;
}
}

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

if($_POST['submit'])
{
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">';

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'.$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>";
}
?>
[/PHP]
May 11 '07 #3
ak1dnar
1,584 Expert 1GB
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

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

Similar topics

6
by: x. zhang | last post by:
Hi Guys, We know that we can use <input type=file ...> to upload one file per time to the server. My question is if there are some way to upload multiple files per time to the server. (Of...
1
by: makthar | last post by:
Hi Everyone: I want to make a page for the users to be able to upload multiple files to the server. Presently I use a html file field but it allows selection of a single file only. Does any...
1
by: Susan | last post by:
Is it possible to use PHP with VBScript or JavaScript to upload multiple files. I'd like to automate the upload of a complete directory (not using FTP). I don't need a common form with several...
3
by: JFB | last post by:
Hi All, It's a way to upload multiple files on a web site using vb.net 2005? I see the uploadFile tool, but it's only for one file. Any ideas, examples, links??? Tks in advance JFB
0
by: deepaks85 | last post by:
Dear Friends, I am trying to upload multiple files. But I can't find why it is not working fine. Here is the code......... numfile.php <form method="POST" action="fileupload.php"> <p...
0
by: deepaks85 | last post by:
Dear Friends, I am trying to upload multiple files. But I can't find why it is not working fine. Here is the code......... numfile.php <form method="POST" action="fileupload.php"> <p...
10
by: Sebarry | last post by:
Hi, I'm using the code at http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/ to upload multiple files with a single file element. It works fine...
43
by: bonneylake | last post by:
Hey Everyone, Well this is my first time asking a question on here so please forgive me if i post my question in the wrong section. What i am trying to do is upload multiple files like gmail...
0
AnuSumesh
by: AnuSumesh | last post by:
Hi We have an application where we can upload file from client machine to any shared device on the network. Now our requirement is to upload multiple files over the network. e.g. to path...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.