Help please with $_FILES

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

    Help please with $_FILES

    I have searched and have not gotten an understanding of $_FILES. I am
    trying to do an upload to a directory "tmpdir" on the server. I have a
    field defined as:

    File name: <input name="filename" type="file" id="filename">

    In my PHP code I have (with diagnostics):

    echo "Will try to upload a file <br>";
    echo "Tmp_Name: ".$_FILES['filename']['tmp_name']."<br>";
    echo "Name: ".$_FILES['filename']['name']."<br>";
    echo "Size: ".$_FILES['filename']['size']."<br>";
    echo "Type: ".$_FILES['filename']['type']."<br>";
    if ($_FILES['filename']['type'] == "mid/wav"){
    echo "File of proper type <br>";
    copy ($_FILES['filename']['tmp_name'],
    "tmpdir/".$_FILES['filename']['name'])
    or die ("Could not copy");
    echo "";
    echo "Name: ".$_FILES['filename']['name']."<br>";
    echo "Size: ".$_FILES['filename']['size']."<br>";
    echo "Type: ".$_FILES['filename']['type']."<br>";
    echo "Copy Done....";
    }

    There are two problems.
    1 - It doesn't enter to do the copy even though the file is a .mid file.
    2 - The $_FILES['filename'] is empty.

    I run the "browse" button and select that a file. Why is the $_FILES
    superglobal empty?

    If I comment out the "if" line and closing "}", the copy fails with a "Could
    not copy", as expected since the filenames are empty.

    Can someone please help me? (I have only been at this for a short while).

    Shelly


  • Geoff Berrow

    #2
    Re: Help please with $_FILES

    I noticed that Message-ID: <nL-dnawWlvlgxlXfRV n-tQ@comcast.com> from
    Shelly contained the following:
    [color=blue]
    > File name: <input name="filename" type="file" id="filename">[/color]

    Make sure you have this in a form including the following:
    <form ENCTYPE="multip art/form-data" method="POST" action="">



    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • Shelly

      #3
      Re: Help please with $_FILES


      "Geoff Berrow" <blthecat@ckdog .co.uk> wrote in message
      news:d0ugc1pman 8sb1d2k13nq6jnn taak7jpv0@4ax.c om...[color=blue]
      >I noticed that Message-ID: <nL-dnawWlvlgxlXfRV n-tQ@comcast.com> from
      > Shelly contained the following:
      >[color=green]
      >> File name: <input name="filename" type="file" id="filename">[/color]
      >
      > Make sure you have this in a form including the following:
      > <form ENCTYPE="multip art/form-data" method="POST" action="">[/color]

      It is enclosed in:

      <form enctype="multip art/form-data" action="thisfor m.php" method="POST">

      Shelly


      Comment

      • Daniel Tryba

        #4
        Re: Help please with $_FILES

        Shelly <sheldonlg.news @asap-consult.com> wrote:
        [file uploading code][color=blue]
        > There are two problems.
        > 1 - It doesn't enter to do the copy even though the file is a .mid file.
        > 2 - The $_FILES['filename'] is empty.
        >
        > I run the "browse" button and select that a file. Why is the $_FILES
        > superglobal empty?
        >
        > Can someone please help me? (I have only been at this for a short while).[/color]

        A clear case of RTFM. Seeing your code I don't know where you got it
        from, but it's definetly not from

        which you should try first.

        While your posted code is not complete I can only guess you didn't
        supply the correct encoding type to the form necessary for uploading:
        enctype="multip art/form-data"

        Comment

        • Shelly

          #5
          Re: Help please with $_FILES


          "Daniel Tryba" <partmapsswen@i nvalid.tryba.nl > wrote in message
          news:42c87db7$0 $74303$c5fe704e @news6.xs4all.n l...[color=blue]
          > Shelly <sheldonlg.news @asap-consult.com> wrote:
          > [file uploading code][color=green]
          >> There are two problems.
          >> 1 - It doesn't enter to do the copy even though the file is a .mid file.
          >> 2 - The $_FILES['filename'] is empty.
          >>
          >> I run the "browse" button and select that a file. Why is the $_FILES
          >> superglobal empty?
          >>
          >> Can someone please help me? (I have only been at this for a short
          >> while).[/color]
          >
          > A clear case of RTFM. Seeing your code I don't know where you got it
          > from, but it's definetly not from
          > http://www.php.net/manual/en/features.file-upload.php
          > which you should try first.[/color]

          I tried to find the FM using the search in www.php.net, but couldn't find
          what you just pointed to. Thanks. I'll read that one.
          [color=blue]
          >
          > While your posted code is not complete I can only guess you didn't
          > supply the correct encoding type to the form necessary for uploading:
          > enctype="multip art/form-data"[/color]

          .....however, I **DID** supply the proper encoding.

          Shelly


          Comment

          • Shelly

            #6
            Re: Help please with $_FILES


            "Daniel Tryba" <partmapsswen@i nvalid.tryba.nl > wrote in message
            news:42c87db7$0 $74303$c5fe704e @news6.xs4all.n l...[color=blue]
            > Shelly <sheldonlg.news @asap-consult.com> wrote:
            > [file uploading code][color=green]
            >> There are two problems.
            >> 1 - It doesn't enter to do the copy even though the file is a .mid file.
            >> 2 - The $_FILES['filename'] is empty.
            >>
            >> I run the "browse" button and select that a file. Why is the $_FILES
            >> superglobal empty?
            >>
            >> Can someone please help me? (I have only been at this for a short
            >> while).[/color]
            >
            > A clear case of RTFM. Seeing your code I don't know where you got it
            > from, but it's definetly not from
            > http://www.php.net/manual/en/features.file-upload.php
            > which you should try first.
            >
            > While your posted code is not complete I can only guess you didn't
            > supply the correct encoding type to the form necessary for uploading:
            > enctype="multip art/form-data"\[/color]

            Here is the complete section and it still doesn't work:

            <p>
            <label></label>
            <br>
            <label> </label>
            </p>
            <form enctype="multip art/form-data" action="thisfor m.php" method="POST">
            <input type="hidden" name="MAX_FILE_ SIZE" value="30000">
            <p>File name: <input name="filename" type="file" id="filename">
            </p>
            <p>Descriptio n: <input name="descripti on" type="text"
            id="description ">
            <label> </label>
            </p>
            <p>
            <label> </label>
            <input name="submit" type="submit" value="Add Entry">
            </p>
            </form>


            Comment

            • Shelly

              #7
              Re: Help please with $_FILES

              I have absolutely NO idea what happened, but it is working now. I really
              didn't change anything. I went to the simple file where I got the method
              and tried that one. It worked. So I compared with the one I wanted and
              nothing was different. I moved a few echos, I and tried again and it
              worked.

              Thanks guys, the mystery continues but at least it is working now.

              Oh, how do I specify multiple types. Right now I have "audio/mid", but I
              would like to also allow .wav files.


              Shelly


              Comment

              Working...