Web lists-archives.com

Re: [PHP] Using $_FILES as conditional along with $_POST

On Sep 21, 2015, at 4:26 PM, Aziz Saleh wrote:

On Mon, Sep 21, 2015 at 7:18 PM, Jeffry Killen <jekillen@xxxxxxxxxxx> wrote:

Hello all:
Thanks for just being here....

I had a very vexing problem and in composing the text of the question
I hit on the answer to the problem an the solution.

It involves the html form attribute enctype="multipart/form-data"
used for uploading files to the server, and the $_FILES superglobal.

It appears that php creates the $_FILES global when it sees this
enctype header in a post request, whether or not there are files
to be uploaded.


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Are you asking why it is doing it?

No, not exactly, as a matter of fact I am not asking anything
at this point. I determined, tentatively what I need to know
to solve a problem with post request from html page that
contained an enctype attribute with value multipart/form-data
for uploading files. The problem occurs when another set
of form elements in the same form element, not concerned
with file uploads, was being submitted, with the enctype and
MAX_FILE_SIZE  hidden field  still present.

The solution is to revise the javascript used for form submission.
It can add the enctype attribute and fill out the hidden field at the last
step before calling submit() to actually upload the file. In this way
all the other form configurations ( four different configurations including
the uploading facility) will definitely not have these elements present
when they are submitted.

I had this conditional in the php side:
if($_FILES && POST)
   // supposed to just process uploads
   // but this code is being run when other
  // parts of the form that don't upload files
  // are submitted: most likely because the enctype attribute
  // and the MAX_FILE_SIZE hidden fields are presented.


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php