SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Upload form

  1. #1
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    Norway
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Upload form

    I have made an upload form that uploads files.

    Its a single file upload form, but I want the user to upload over and over again, and place all the files into an array that I can use on the next page to give the user a list of all he's uploaded files..

    Hope you understand what I'm trying to do
    Thanks for your time

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Use an array in the user's session (ex: $_SESSION['filelist']) to store the names of the uploaded files. That way, the list can be accessed on all pages (assuming that all pages has session_start on them).
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    Norway
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how do I make an array where I can append a new value each time the user click the submit button ?

    I tried making one, but it only show the last uploaded picture

  4. #4
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    This will create the array if it do not exist:

    PHP Code:
    if( !isset($_SESSION['filelist']) )
      
    $_SESSION['filelist'] = array(); 
    And this will append an element to the end of it:

    PHP Code:
    $_SESSION['filelist'][] = 'filename'
    Let me know if you need more help.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  5. #5
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    Norway
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks it works now Just another question.

    I'm using a for loop to list the pictures, but I'm not sure how to make this loop more dynamic because now I didnt know what else to do than set a static 10 value to end the loop, and I would also need to know how I can stop the loop after the last image ?

    Thanks

    Code
    PHP Code:
    if (isset($_SESSION['filelist'])) {
        for (
    $i 0$i <= 10$i++) {
            echo 
    "<a href=\"#\" onClick=\"window.open('".$_SESSION['filelist'][$i] ."','mywindow','width=400,height=200')\"><img src=\"".$_SESSION['filelist'][$i] ."\" height=\"50px\" /></a>";
            } 

  6. #6
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You can use sizeof to get the number of elements in the array.

    PHP Code:
    for( $i 0$i sizeof($_SESSION['filelist']); $i++ ) { 
    You can also use a foreach loop.

    PHP Code:
    foreach( $_SESSION['filelist'] as $i => $filename ) { 
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  7. #7
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    Norway
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, works great now


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •