Is $_FILES more secure than $_POST? Which should I use?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jankie
    New Member
    • May 2007
    • 58

    Is $_FILES more secure than $_POST? Which should I use?

    Greetings !
    i hope someone can give me some insights as to what upload method to use of these and if any comparison
    I found that :
    if (isset($_FILES['userfile'])) {

    works for me in some applications where:
    if(isset($_POST['submit']))
    does not

    How secure is the first method ?

    Thank you very much in advance !
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Changed thread title to better match contents.

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      Originally posted by Jankie
      Greetings !
      i hope someone can give me some insights as to what upload method to use of these and if any comparison
      I found that :
      if (isset($_FILES['userfile'])) {

      works for me in some applications where:
      if(isset($_POST['submit']))
      does not

      How secure is the first method ?

      Thank you very much in advance !
      I think that will only work when a file has been uploaded. I think the only reason why the second one will not work is because you have titled the submit button differently. Remember, the POST array is case sensitive!

      Comment

      • Jankie
        New Member
        • May 2007
        • 58

        #4
        Well,if(isset($ _POST['submit']) DOES work

        but if(isset($_POST['submit']) && $_FILES['userfile']['size'] > 0) {
        does not work for me in conjunction with:
        if ($_FILES['userfile']['error'] == UPLOAD_ERR_OK) {

        Comment

        • Motoma
          Recognized Expert Specialist
          • Jan 2007
          • 3236

          #5
          I don't know what you are looking for. Perhaps you could carefully word a question that accurately expresses the difficulties you are having as well as alludes to what you need for information from me. It also helps if you post the relevant segments of code, and delineate what is happening, what isn't happening, and what you want to happen.

          Comment

          • Jankie
            New Member
            • May 2007
            • 58

            #6
            [code=php]
            <?php
            if(isset($_POST['submit']) && $_FILES['userfile']['size'] > 0)
            if ($_FILES['userfile']['error'] == UPLOAD_ERR_OK) {
            $tmpName = $_FILES['userfile']['tmp_name'];
            $fileName = $_FILES['userfile']['name'];
            $uploaddir = 'uploads/';
            $uploadfile = $uploaddir.base name($_FILES['userfile']['name']);
            if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadfile)) {
            echo 'File Uploaded!';
            }
            else {
            echo 'Upload failed.';
            }
            }
            elseif ($_FILES['userfile']['error'] == UPLOAD_ERR_FORM _SIZE) {
            echo 'File exceeds allowed upload file size.';
            }
            ?>
            ---corretly set Form here----
            if(isset($_POST['submit']) && $_FILES['userfile']['size'] > 0) does not work but

            if (isset($_FILES['userfile'])) { does
            [/code]
            Last edited by Motoma; Jun 5 '07, 06:52 PM. Reason: Code tags added.

            Comment

            • Jankie
              New Member
              • May 2007
              • 58

              #7
              if(isset($_POST['submit'])) { alone also work
              the submit button is named submit

              Comment

              • Motoma
                Recognized Expert Specialist
                • Jan 2007
                • 3236

                #8
                Do a print_r on your FILES array and see what the size is showing.

                Comment

                • Jankie
                  New Member
                  • May 2007
                  • 58

                  #9
                  Thank you Motoma for taking the time to look at it
                  I'll try your suggestion,seem s the right direction. I just want the :
                  && $_FILES['userfile']['size'] > 0) part to ensure no 0 byte file is uploaded(for security reasons) instead of inserting another if/else statement.

                  Comment

                  • Motoma
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3236

                    #10
                    Originally posted by Jankie
                    Thank you Motoma for taking the time to look at it
                    I'll try your suggestion,seem s the right direction. I just want the :
                    && $_FILES['userfile']['size'] > 0) part to ensure no 0 byte file is uploaded(for security reasons) instead of inserting another if/else statement.
                    Anytime. Post back and let me know if that gave any insight into the problem.

                    Comment

                    Working...