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($...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
"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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|