Web Analytics Made Easy -
StatCounter multiple file uploads with PHP - CodingForum


No announcement yet.

multiple file uploads with PHP

  • Filter
  • Time
  • Show
Clear All
new posts

  • multiple file uploads with PHP

    Hello everyone--

    I have an admin page that I am working on that is a top 25 list that needs to have a file uploaded for each item. I have a page setup that has the list of all the info displayed to be editable. I am having a problem with the multiple instances of the <input type=file> entities.

    Each file input is named "upFile".$i where $i is the counter [1-25]. When I try to reference the $upFile.$i, PHP doesn't put the two together and it errors out. If I use $upFile1, $upFile2, ..etc I have no problems but that's just ugly! Arg.

    Does anyone have any ideas on how to accomplish this with out explicitly typing each value out? At this point any ideas would be GREATLY appreciated. Thanks.

  • #2
    I would suggest you name your fields like so ...

    <input type="file" name="upFile[1]" />

    etc , then the returned $_FILES['upFile'] will be an array which you can loop through.

    but to answer your question ...

    PHP Code:
    for( $x=1$x<5; ++$x ){
    $fieldname= ${'upFile' $x};
    /*do your other stuff with $_FILES[$fieldname];*/ 
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)