Q:

How to set the max upload size value within php (not php.ini)?

I was trying to limit the size to 50bytes just to test it, but this approach isn't working for some reason.  I don't have access to the php.ini and would like to do this with code if possible.
The form:
 <form action='uploadFile.php' target='uploadIframe' method='post' enctype='multipart/form-data'>
<div class='fieldRow'>
 <label>Select the file: </label>
 <input type='file' name='file' id='file' onChange='submitForm1(this)' />

 </div>
    </form>
<iframe style='border:0;' id='uploadIframe' name='uploadIframe'></iframe>
  <div id='successMessage'></div>

uploadFile.php
<!doctype html>
<html lang="en">
<head>
 <script src="//code.jquery.com/jquery-1.10.2.js"></script>
 </head>
 <body>
 <?php
 $upload_dir = "../sitedata/auditfiles";
 $result["status"] = "200";
 $result["message"]= "Error!";

 if(isset($_FILES['file'])){

    echo "Uploading file... <br />";

     if ($_FILES['file']['error'] == UPLOAD_ERR_OK) {
          $filename = $_FILES['file']['name'];
          move_uploaded_file($_FILES['file']['tmp_name'],
          $upload_dir.'/'.$filename);
           $result["status"] = "100";
          $result["message"]="File was uploaded successfully!";

Here is the issue:
      }elseif ($_FILES["file"]["size"] > 50) {
      $result["status"] = "200";
      $result["message"]= "Error: Document size exceeds maximum limit of 5 MB.  Please reduce the file size and retry upload";
        }

     //initial code that worked but only does it through php.ini
      /*    elseif ($_FILES['file']['error'] == UPLOAD_ERR_INI_SIZE) {
           $result["status"] = "200";
              $result["message"]= "The file is too big!";/**/
     } else {
             $result["status"] = "500";
           $result["message"]= "Unknown error!";
       }
      }
     ?>
    </body>
    </html>

     <script>
      $(function () {
            $('#successMessage', window.parent.document).html('<?php echo htmlspecialchars($result["message"]); ?>');
     });
    </script>

 function submitForm1(upload_input_field){
  //alert("works");
   upload_input_field.form.submit();
   upload_input_field.disabled = true;
   return true;

 }

A:

upload_max_filesize is in PHP_INI_PERDIR mode and from the PHP documentation:

PHP_INI_PERDIR Entry can be set in php.ini, .htaccess, httpd.conf or .user.ini (since PHP 5.3)

So, your choices are php.ini, .htaccess, httpd.conf or .user.ini, you can't set it in the script using ini_set.

