SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Oct 2005
    Posts
    288
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    $_FILES skill deficiency

    my $_FILES comes up NULL when I use <form ... enctype="multipart/form data"> ... <input ... type="file" />.

    This is my first attempt at $_FILES.

    I'm attempting to convert Mayank Gandhi's "Build and Automated PHP Gallery System in Minutes ( http://www.sitepoint.com/article/php...system-minutes ) to MVC.

    Here's the relevant part of my form :
    Code:
       <div id="picform">
        <form name="picForm"
          enctype="multipart/form data"
          action="/legacy/index.php?pageId=gallery&amp;action=validate"
          method="post">
         <fieldset id="fieldSelect"> 
          <legend>Select Category</legend>
    
          <div id="divcategory">
            <select name="category">
                  <option value="1">Test Gallery</option>
    
            </select>
           </div> <!-- divcategory -->
         </fieldset> <!-- id="fieldSelect" -->
             <fieldset class="photoset">
    
        <legend>Upload Pictures From</legend>
         <label for="photoFilename[]">Photo1</label>
    
         <input name="photoFilename[]" type="file" />
         
        <label for="photoCaption[]">Caption:</label>
    
        <textarea name="photoCaption[]" cols="30" rows="1"></textarea>
    
       </fieldset>
    
         <input type="submit" name="optPic" id="optPic" class="clsOptions" value="Add Picture" />
        </form>
       </div> <!-- "picform" -->
    The action sends it to my index.php which instantiates the pageId (gallery) controller which contains
    Code:
       case "validate":
        var_dump($_FILES[0]);
        var_dump($_FILES[0]['name']);
        var_dump($_FILES['photoFilename']);
        var_dump($_FILES['photoFilename']['name']);
        var_dump($_FILES['photoFilename[]']);
        var_dump($_FILES['photoFilename[]']['name']);
    The result of these var_dumps is
    NULL NULL NULL NULL NULL NULL

  2. #2
    SitePoint Addict mmanders's Avatar
    Join Date
    Jul 2006
    Location
    Edinburgh, Scotland
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I could be wrong but I think the enctype should be
    [HTML]
    ...enctype="multipart/form-data"...
    </HTML>

    Note the hyphen (-) in the enctype. Your example didn't have this.

  3. #3
    SitePoint Addict
    Join Date
    Oct 2005
    Posts
    288
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That's it. Thank you (I won't admit to the number of hours I wasted on this.)

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    It usually the really simple mistakes that plague our brains over and over again.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



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
  •