Hi everybody !
I'd be grateful if anyone can point out to me what is missing to get following code working - <?php
-
$filename = $_FILES['userfile']['name'];
-
$tempname = $_FILES['userfile']['tmp_name'];
-
------
-
-------
-
?>
-
-
<form action="file-upload.php" method="post" enctype="multipart/form-data">
-
Send these files:<br />
-
<input name="userfile1" type="file" /><br />
-
<input name="userfile2" type="file" /><br />
-
<input type="submit" value="Submit" />
-
</form>
-
-
foreach ($_FILES as $file) {
-
-
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$file], $uploadfile)) {
-
-
..........
-
..........
-
-
... }
[Please use CODE tags when posting source code. Thanks! --pbmods]
I also wonder if this would be enough to insert multiple files at once in a db.
My gratitude in advance !
6 2002
Heya, Jankie.
Your inputs are going to populate $_FILES['userfile1'] and $_FILES['userfile2'].
If in doubt:
Alternatively, if you want to allow for the possibility of more than 2 files, you can name your inputs 'userfile[]', which will create $_FILES['userfile'][0], $_FILES['userfile'][1], $_FILES['userfile'][2], etc.
E.g.: -
<input name="userfile[]" type="file" /><br />
-
<input name="userfile[]" type="file" /><br />
-
<input name="userfile[]" type="file" /><br />
-
.
-
.
-
.
-
<input type="button" onclick="createFileInput();" value="Add Another" />
-
Thank you Pbmods for your readiness to offer a hand(as always :)
Yes,print_r positive
Now if you can afford a bit more kindness trespassing,which do you think is the best(or the correct) way of finishing it up this multiple uploads ? - foreach ($_FILES["userfile"]["error"] as $file) {
-
if (move_uploaded_file($file['userfile']['tmp_name'][$file], $uploadfile)) {
-
....
-
}
or - foreach ($_FILES["userfile"]["error"] as $file) {
-
move_uploaded_file($file["userfile"]["tmp_name"],$file["userfile"]["name"],$uploadfile)
-
..
-
}
Heya, Jankie.
What you'll want to do is iterate through $_FILES itself: - foreach($_FILES as $array)
Since $_FILES is going to look like this: -
$_FILES = array(
-
'userfile1' => array( // <-- We want to work with this array first...
-
'name' => 'apicture.jpg',
-
'type' => 'image/jpeg',
-
'size' => '45000',
-
'tmp_name' => '/tmp/php_123456abcd',
-
'error' => 0
-
),
-
'userfile2' => array( // ... then this one.
-
'name' => 'anotherpicture.jpg',
-
'type' => 'image/jpeg',
-
'size' => '48000',
-
'tmp_name' => '/tmp/php_dcba_654321',
-
'error' => 0
-
)
-
);
-
Probably what you'll want to do first is make sure that each file was uploaded correctly: -
$errors = array();
-
foreach($_FILES as $key => $array)
-
if($array['error'] !== UPLOAD_ERR_OK)
-
$errors[] = "$key had error {$array['error']}!";
-
-
if(! empty($errors))
-
exit(implode('<br />', $errors));
-
Once you've determined that there were no errors, then you can process your files: -
foreach($_FILES as $key => $array) {
-
if(! move_uploaded_file( $array['tmp_name'], $array['name'] ))
-
$errors[] = "$key could not be moved!";
-
}
-
-
if(! empty($errors))
-
exit(implode('<br />', $errors));
-
Thanks for using CODE tags! Did you know that you can specify a language for your CODE tags to make your source code easier to read?
You will still need to use [/code] to close your code blocks, regardless of the language, but you can the use one of these tags to open your code block:
[code=html]
[code=javascript]
[code=php]
and so on.
Thanks!
MODERATOR
Thanks a lot Pbmods
Interesting the code thing,never heard of it as a closing tag
Time to sleep for the day
Happy weekdays ahead !
Heya, Jankie.
Interesting the code thing,never heard of it as a closing tag
Yeah, it can be a little confusing. For more info, check out the 'REPLY GUIDELINES' box on the right side of the page when you post.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: lion |
last post by:
I get these errors when uploading images via a web page:
(the page still uploads the images but reports these errors?)
Warning: fopen(D:\php\uploadtemp\php1FC7.tmp) : failed
to create stream: No...
|
by: Ron Brennan |
last post by:
Good afternoon.
The entire task that I'm trying to achieve is to allow a user to browse and
upload multiple files simultaneously, hiding the Browse button of <input>
tags of type="file" and...
|
by: Ron Brennan |
last post by:
Good afternoon.
The entire task that I'm trying to achieve is to allow a user to browse and
upload multiple files simultaneously, hiding the Browse button of <input>
tags of type="file" and...
|
by: Jason |
last post by:
Hi
I have this web application for an intranet. I would like to be able to
upload 1 or more files from the client machine. for example: the client is
working with 10 files and after he is done...
|
by: Sky Sigal |
last post by:
I have created an IHttpHandler that waits for uploads as attachments for a
webmail interface, and saves it to a directory that is defined in
config.xml.
My question is the following:
assuming...
|
by: Corey Erkes |
last post by:
I am using ASP.Net with C# as the code behind and am trying to upload
multiple files with the HTMLInputFile Control. I am able to browse, select
a file, and finally upload, but only one file at a...
|
by: tshad |
last post by:
I have a page that I am using for multiple uses that includes reposting of
the page as well as going to another page where the "form" tag would be
something like:
<form id="something"...
|
by: Sönke Greve |
last post by:
Hi there,
i want to enable uploading lots of images and later display it as an online
gallery.
Therefore i need a way of using the FileUpload Component with selecting
multiple files or a whole...
|
by: Chris |
last post by:
I have a meetings section I'm developing on our intranet. Using PHP/MySQL.
Meeting info and Meeting docs reside on 2 related tables in the db. Users
may want to upload anywhere from 1 to 10 or...
|
by: Zoliq |
last post by:
Hi,
I have a serious problem. I'm currently developing an application in which the user should upload many files (600-700 xml files). I've searched the web for a while and so far I realized that...
|
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,...
|
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$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |