$_FILE variables returning null when in body of page.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bill

    $_FILE variables returning null when in body of page.

    I am a relative newbie to PHP, but not to other languages.
    I wrote a test script to upload files. In the php section above
    the page I get the expected content of the $_FILES array.

    When I have a php section in the body, the $_FILES array
    variables return nothing.
    --------here is the page that is the action of the post-------
    <?php

    echo "The array<br />";
    print_r($_FILES );
    echo "<br />--------------------------------";
    echo "<br />temp-name-php:";
    echo $_FILES["test-img"]["tmp_name"];
    echo "<br />name-php:";
    echo $_FILES["test-img"]["name"];

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=us-ascii" />
    <title>do test upload</title>
    </head>
    <body>
    <p>test file upload-5</p>

    <p><? echo "this is a test <br />" ?>
    temp name- <? echo $_FILES["test-img"]["tmp_name"] ? <br />
    name -<?php echo $_FILES["test-img"]["name"]; ?<br />
    size -<?php echo $_FILES["test-img"]["size"]; ?<br />
    type -<?php echo $_FILES["test-img"]["type"]; ?<br />
    </p>
    </body>
    </html>
    -------------------------------------------------------

    Any suggestions as to why I get the null returns from the $_FILE
    array ?
  • NC

    #2
    Re: $_FILE variables returning null when in body of page.

    bill wrote:
    >
    I wrote a test script to upload files. In the php section above
    the page I get the expected content of the $_FILES array.
    >
    When I have a php section in the body, the $_FILES array
    variables return nothing.
    ....
    Any suggestions as to why I get the null returns from the
    $_FILE array ?
    I would guess, there's something wrong with the form you are
    using to upload files. Most likely, you forgot to specify
    enctype="multip art/form-data" in your form definition...

    Cheers,
    NC

    Comment

    • bill

      #3
      Re: $_FILE variables returning null when in body of page.

      NC wrote:
      bill wrote:
      >I wrote a test script to upload files. In the php section above
      >the page I get the expected content of the $_FILES array.
      >>
      >When I have a php section in the body, the $_FILES array
      >variables return nothing.
      ...
      >Any suggestions as to why I get the null returns from the
      >$_FILE array ?
      >
      I would guess, there's something wrong with the form you are
      using to upload files. Most likely, you forgot to specify
      enctype="multip art/form-data" in your form definition...
      >
      Cheers,
      NC
      >
      Actually the file uploads fine, the $_FILES array gets loaded and
      will display the values in the script that lives above the
      webpage code. The $_FILES array returns null values when I have
      a section of php in the body of the page.
      here is some of my code:---------------------
      <?
      echo "The array<br />";
      print_r($_FILES );
      echo "<br />--------------------------------";
      echo "<br />temp-name-php:";
      echo $_FILES["test-img"]["tmp_name"];
      echo "<br />name-php:";
      echo $_FILES["test-img"]["name"];
      echo "<br />---------------------<br />";
      ?>

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type"
      content="text/html; charset=us-ascii" />
      <title>do test upload</title>
      </head>
      <body>
      <p>test file upload-5</p>
      <p>
      temp name- <? echo $_FILES["test-img"]["tmp_name"] ? <br />
      name -<?php echo $_FILES["test-img"]["name"]; ?<br />
      size -<?php echo $_FILES["test-img"]["size"]; ?<br />
      type -<?php echo $_FILES["test-img"]["type"]; ?<br />
      </p>
      </body>
      </html>
      --------------------------------
      the $_FILES vars in the body return blank or null values

      bill

      Comment

      • Michael Fesser

        #4
        Re: $_FILE variables returning null when in body of page.

        ..oO(bill)
        >Actually the file uploads fine, the $_FILES array gets loaded and
        >will display the values in the script that lives above the
        >webpage code. The $_FILES array returns null values when I have
        >a section of php in the body of the page.
        >here is some of my code:---------------------
        >[...]
        The code works here (PHP 5.2), except for
        ><?
        which should be <?php.

        Micha

        Comment

        • bill

          #5
          Re: $_FILE variables returning null when in body of page.

          Michael Fesser wrote:
          .oO(bill)
          >
          >Actually the file uploads fine, the $_FILES array gets loaded and
          >will display the values in the script that lives above the
          >webpage code. The $_FILES array returns null values when I have
          >a section of php in the body of the page.
          >here is some of my code:---------------------
          >[...]
          >
          The code works here (PHP 5.2), except for
          >
          ><?
          >
          which should be <?php.
          >
          Micha
          Thanks Michael;

          It turned out that I made a little error midway down the code.
          While testing to see if the $_FILES array exists, I was setting
          it to null.

          Which explains a lot of problems.

          Thanks.

          bill

          Comment

          • dyer85

            #6
            Re: $_FILE variables returning null when in body of page.

            I know the problem's solved, but I thought I'd share some info on what
            became a serious headache for me. I set the MAX_FILE_SIZE hidden input
            variable in the HTML form, and didn't realize the limit was too small
            for several of the expected files for upload. For some reason, I wasn't
            making the connection as to why certain files weren't making it into
            the $_FILES hash. Lol! Maybe it's just me.

            If you don't bother setting this, then php.ini will handle the limits.

            On Nov 25, 7:27 am, bill <nob...@spamcop .netwrote:
            Michael Fesser wrote:
            .oO(bill)
            >
            Actually the file uploads fine, the $_FILES array gets loaded and
            will display the values in the script that lives above the
            webpage code. The $_FILES array returns null values when I have
            a section of php in the body of the page.
            here is some of my code:---------------------
            [...]
            >
            The code works here (PHP 5.2), except for
            >
            <?
            >
            which should be <?php.
            >
            MichaThanks Michael;
            >
            It turned out that I made a little error midway down the code.
            While testing to see if the $_FILES array exists, I was setting
            it to null.
            >
            Which explains a lot of problems.
            >
            Thanks.
            >
            bill

            Comment

            Working...