problems with scalars

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt Schroeder

    problems with scalars

    Hello everyone -
    I wrote a function that handles uploads, and to call it variables are
    defined like this:
    function handleupload($g ofile, $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





  • Steven Vasilogianis

    #2
    Re: problems with scalars

    "Matt Schroeder" <wnawombat41@co mcast.net> writes:
    [color=blue]
    > [..] 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?[/color]

    Here's an example:

    for ( $fileIndex = 0; $fileIndex < $max_file_uploa ds; ++$fileIndex ) {
    move_uploaded_f ile($_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

    Comment

    Working...