SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getting $HTTP_POST_VARS proplem

    I am working on an image upload script and I've tried to use the variables from $HTTP_POST_FILES however it seems that no matter how I try to get the variables, they are always empty -- even though they are populated when checking phpinfo();

    HTTP_POST_FILES["binFile"]
    Array
    (
    [name] => arrow-block.gif
    [type] => image/gif
    [tmp_name] => /var/tmp/phph60272
    [size] => 857
    )


    I got some info on it from php.net and attempt to echo as they have on their site however it displays nothing.

    echo $HTTP_POST_FILES['binFile']['name']."<br>";

    I am attempting to get size/extension of the file to determine if its a valid extension and within the valid filesize range.

    Is this a server issue or just my php newbie-ness?

    Thanks.
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jason,

    A couple of things. Your form input is named binFile right? Also are you using this inside a function, if so you need to globalize the array inside the function. I made a small test, and this works, so make sure you have these things covered.

    PHP Code:
    <?
        
    //Check for successful upload
        
    if($HTTP_POST_FILES['userfile']) {
            foreach(
    $HTTP_POST_FILES['userfile'] as $key => $val) {
                print 
    "$key => $val<br>";
                }
            }


    ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
    <head>
        <title>Untitled</title>
    </head>

    <body>
    <?=$error?>
    <form action="<?=$PHP_SELF?>" method="post" enctype="multipart/form-data">
    <input type="file" name="userfile"><br>
    <input type="submit" name="submit" value="Upload File">
    </form>

    </body>
    </html>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Addict
    Join Date
    Sep 2000
    Location
    Ontario, Canada
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your message... as you said, it turns out that I forgot to register $HTTP_POST_FILES as a global. I guess I should keep a better eye on my errors before I post here.

    Everything is working great now.

    Thanks again.
    Jason Dulberg
    Extreme MTB
    http://extreme.nas.net


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
  •