SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    understanding arrays

    I have this bit if code to upload an image
    HTML Code:
    <input type='file' name='file1' id='file1'>
    PHP Code:
    if($_FILES['file1']['error'] > 0){
        die(
    'An error ocurred when uploading.');
    }
    if((
    $_FILES['file1']['type'] != 'image/png') && ($_FILES['file1']['type'] != 'image/gif') && ($_FILES['file1']['type'] != 'image/jpeg') && ($_FILES['file1']['type'] != 'image/bmp'))
    {
        die(
    'Unsupported filetype uploaded.');
    }
    if(
    $_FILES['file1']['size'] > 102400){
        die(
    'File uploaded exceeds maximum upload size.');
    }
    $now time(); 
    while(
    file_exists($uploadFilename 'uploads/'.$now.'-'.$_FILES['file1']['name'])) 

        
    $now++; 

    if(!
    move_uploaded_file($_FILES['file1']['tmp_name'], $uploadFilename)){
        die(
    'Error uploading file - check destination is writeable.');

    But i'd like to upload an array of images also, but am confused as what is the best way to do it if I simply make this change
    HTML Code:
    <input type='file' name='image[]' id='file1'>
    I really want to understand this process, so I gather I first need to check if an image has even been uploaded
    PHP Code:
    if (!empty($_FILES['image'][]['name'])) { 
    then use a foreach statement to run code on each upload
    PHP Code:
    //I really am confused at this point 
    Thanks...
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,014
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    If you're wanting to upload multiple files the script processing them will need to rearrange the contents of the $_FILES array, there was a thread covering that a few months back, off-hand I can't remember what the thread title was
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  3. #3
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    "Oh, and Jenkins--apparently your mother died this morning."


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
  •