Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docs:browsers:posting_forms [2009/06/26 00:32] billhdocs:browsers:posting_forms [2009/11/03 10:17] (current) billh
Line 16: Line 16:
 </form> </form>
 </code> </code>
 +
 +It is common to test for this to determine if a form was posted:
 +<code php>
 +if( $_POST ){
 +  // do something
 +}
 +</code>
 +However, if the only thing in your form was a file input and a submit button, then the post array may be empty.  You should test for the files array instead:
 +<code php>
 +if( $_FILES ){
 +  // do something
 +}
 +</code>
 +
 +===== handling max file size during uploads =====
 +It is advisable to handle file sizes during uploads.  The easiest way to do this is to find out how large the file can be for uploads from apache and/or a php info page.  Then you add this element to the form:<code>
 +<input type="hidden" name="MAX_FILE_SIZE" value="10485760" />
 +</code>
 +
 +Once the form is posted, you can check for errors like this:<code>
 +if( $_POST ){
 + if( isset($_FILES['datafile']) ){
 + if( $_FILES['datafile']['error'] === UPLOAD_ERR_OK ){
 + // process the uploaded file
 + }else{
 + // there was an error
 + }
 + }
 +}
 +</code>
 +
 +You can run a switch/case block if you prefer, and handle each error code differently.  See this page for more information about the file upload error codes:
 +  * http://www.php.net/manual/en/features.file-upload.errors.php
  
 ===== multi select as an array ===== ===== multi select as an array =====
  • docs/browsers/posting_forms.1245997955.txt.gz
  • Last modified: 2009/06/26 00:32
  • by billh