problems with scalars

This is a discussion on problems with scalars within the PHP Language forums, part of the PHP Programming Forums category; Hello everyone - I wrote a function that handles uploads, and to call it variables are defined like this: function handleupload($...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-25-2003
Matt Schroeder
 
Posts: n/a
Default problems with scalars

Hello everyone -
I wrote a function that handles uploads, and to call it variables are
defined like this:
function handleupload($gofile, $name, $size, $usersname) {
// the action goes here
}
However, I need to use the $_files array to call the uploaded files in a for
function. The first uploaded file is $_FILES['file1']['tmp_name'], and the
second is $_FILES['file2']['tmp_name'], and so on. How do I use the $i
scalar used in the for loop to replace 1 and 2 in the $_FILES array? I tried
these but they didnt work:

handleupload("$_FILES['file".$i."']['tmp_name']",
"$_FILES['file".$i."']['name']", "$_FILES['file".$i."']['size']",
$_COOKIE['cookie']['id']);
handleupload("$_FILES['file$I']['tmp_name']",
"$_FILES['file$i']['name']", "$_FILES['file$i']['size']", $username);

This is probably simple, but I'm new to this. So, how can I incorporate the
name of a scalar in another scalar's name in order to call a function?

Thanks,
Matt





Reply With Quote
  #2 (permalink)  
Old 07-25-2003
Steven Vasilogianis
 
Posts: n/a
Default Re: problems with scalars

"Matt Schroeder" <wnawombat41@comcast.net> writes:

> [..] The first uploaded file is $_FILES['file1']['tmp_name'], and the
> second is $_FILES['file2']['tmp_name'], and so on. How do I use the $i
> scalar used in the for loop to replace 1 and 2 in the $_FILES array?


Here's an example:

for ( $fileIndex = 0; $fileIndex < $max_file_uploads; ++$fileIndex ) {
move_uploaded_file($_FILES["file$fileIndex"]["tmp_name"], '../incoming');
}

In place, of ["file$fileIndex"] you may also use:

['file' . $fileIndex]

See <http://us2.php.net/manual/en/language.types.string.php> for
explanations on how to handle string interpolation.

HTH,
--
steven vasilogianis
Reply With Quote
Reply


Thread Tools
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:32 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0