FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.

FutureQuest, Inc.
Go Back   FutureQuest Community > General Site Owner Support (All may read/respond) > PHP, Perl, Python and/or MySQL
User Name
Password  Lost PW

Reply
 
Thread Tools Search this Thread Display Modes
Old 12-06-1999, 08:34 PM   Postid: 43366
SneakyDave
Fond of TAZ
 
SneakyDave's Avatar

Forum Notability:
93 pts: Helpful Contributor
[Post Feedback]
 
Join Date: Feb 1999
Posts: 919
File Upload using an array variable

Say I use a FORM that has the ability to upload 5 files at a time.

From this informative page at the PHP site:
http://www.php.net/manual/html/feature-fileupload.html

It says I can extract the name as $userfile_name, and size as $userfile_size, which is pretty handy.

But what if the 5 files I'm uploading are described using an array, say something like:

Code Sample:

<INPUT NAME=&quot;file[]&quot; TYPE=&quot;file&quot; size=50>




How would I access the name and size, because using something like $file[1]_name and $file[1]_size doesn't work.

Thanks for any help.


 



SneakyDave is offline   Reply With Quote
Old 12-06-1999, 08:50 PM   Postid: 43367
Justin
Visitor
 
Justin's Avatar

Forum Notability:
0 pts:
[Post Feedback]
 
Join Date: Jan 1999
Location: Kissimmee, FL
Posts: 3,672
I'm not sure if this will work, but if it does allow the array, use $userfile_name[1] and so on.

If that doesn't work, I'm guessing PHP won't do multiple file uploads simultaneously - something I never thought about. One of my current projects processes up to 10 simultanous uploads, but uses Perl (and does *not* use any libraries for upload processing )...

The PHP idea *might* work, but I'm not sure - you should be able to process the uploads manually as you would in Perl (bypassing the built-in method) but explaining how to do so would take a while (took me a long time and lots of trial/error to figure it out in Perl).

Hope this helps.

------------------
Justin Nelson
FutureQuest Support
Justin is offline   Reply With Quote
Old 12-06-1999, 08:56 PM   Postid: 43368
Justin
Visitor
 
Justin's Avatar

Forum Notability:
0 pts:
[Post Feedback]
 
Join Date: Jan 1999
Location: Kissimmee, FL
Posts: 3,672
DOH! Now that I think about it... don't use the same variable name on all of them - $userfile is just the example they use on PHP.Net

</font><font face="Courier" size="3"><input type=file name=File1>
<input type=file name=File2></font><font face="Verdana, Arial" size="2">

And so on - then you would use $File1_size etc

Hope this helps.

------------------
Justin Nelson
FutureQuest Support
Justin is offline   Reply With Quote
Old 12-06-1999, 08:58 PM   Postid: 43369
SneakyDave
Fond of TAZ
 
SneakyDave's Avatar

Forum Notability:
93 pts: Helpful Contributor
[Post Feedback]
 
Join Date: Feb 1999
Posts: 919
Well, from a little testing, PHP doesn't even like you to use an array to store the file names. After writing a bunch of code that I thought was going to work (using the idea you mentioned and not getting any errors), I realized that the array was empty!

So that didn't work. I suppose I could try to use a loop with variable $x to name each INPUT TYPE=FILE as &quot;file$x&quot;.
And then process each variable using another loop to extract the &quot;file$x_name&quot; and &quot;$file$x_size&quot; values.

I'll have to do some reading to figure out how exactly to get that to work.

Thanks Justin!


SneakyDave is offline   Reply With Quote
Old 12-06-1999, 09:00 PM   Postid: 43370
SneakyDave
Fond of TAZ
 
SneakyDave's Avatar

Forum Notability:
93 pts: Helpful Contributor
[Post Feedback]
 
Join Date: Feb 1999
Posts: 919
Just as an FYI for other people, you can do simultaneous uploads with PHP, but I've only got it to work if the INPUT fields are named differently:

Code Sample:

<INPUT TYPE=FILE NAME=FILE1 TYPE=FILE>
<INPUT TYPE=FILE NAME=FILE2 TYPE=FILE>




SneakyDave is offline   Reply With Quote
Old 12-06-1999, 09:01 PM   Postid: 43371
SneakyDave
Fond of TAZ
 
SneakyDave's Avatar

Forum Notability:
93 pts: Helpful Contributor
[Post Feedback]
 
Join Date: Feb 1999
Posts: 919
Hey Justin, I must have just missed you!

Like you said, yes, you can do multiple files, but PHP doesn't like you putting them in arrays.

I'll work on using what you and I just suggested, and then coding a loop that will parse the correct variable I want to use in a loop, ie. &quot;$file$x&quot;.
SneakyDave is offline   Reply With Quote
Old 12-06-1999, 09:27 PM   Postid: 43372
SneakyDave
Fond of TAZ
 
SneakyDave's Avatar

Forum Notability:
93 pts: Helpful Contributor
[Post Feedback]
 
Join Date: Feb 1999
Posts: 919
Well, I think I almost have it working, using the above code for the form, and something like this for processing:


Code Sample:

    $x=1;
    eval('$name = $file'.$x.'_name;');
    eval('$size = $file'.$x.'_size;');
    eval('$type = $file'.$x.'_type;');
    while($name)
    {
      whatever it is you want to do with $name, $type, and $size

      $x++;
      eval('$name = $file'.$x.'_name;');
      eval('$size = $file'.$x.'_size;');
      eval('$type = $file'.$x.'_type;');
    }



[This message has been edited by SneakyDave (edited 12-06-99)]
SneakyDave is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 visitors)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 10:32 AM.


Running on vBulletin®
Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.
Hosted & Administrated by FutureQuest, Inc.
Images & content copyright © 1998-2013 FutureQuest, Inc.
FutureQuest, Inc.