Before You Begin -- PHP File Upload

php Uploader

PHP File Uploader

Before You Begin

1. Setting temporary file location

PHP File Uploader streams the data into a temporary file while the data is received. By default PHP File Uploader will use the system temporary directory (upload_tmp_dir), which can typically be accessed by all system users. If system temporary directory is not readable or writable by PHP user, you must specify a temporary file location. You should ensure that the PHP user has read/write permission to this specified folder.

You can easily specify the temporary file location using TempDirectory property:

  1. //Register Uploader component to your page   
  2. <?php require_once "phpuploader/include_phpuploader.php" ?>   
  3. <html>   
  4. <body>   
  5.         <form id="form1" method="POST">   
  6.             <?php   
  7.                 // Create Uploader object.   
  8.                 $uploader=new PhpUploader();   
  9.                 // Set a unique name to Uploader   
  10.                 $uploader->Name="myuploader";    
  11.                 // specify the temporary file location using TempDirectory property   
  12.                 $uploader->TempDirectory="/mytempfolder";    
  13.                 // Render Uploader   
  14.                 $uploader->Render();   
  15.             ?>   
  16.         </form>   
  17. </body>   
  18. </html>  

2. Setting MaxSizeKB

For security purpose, you should specify the limit for the size of uploaded file through MaxDataSize, in kilobytes. This limit can be used to prevent denial of service attacks that are caused, for example, by users uploading large files to the server. The default is no limit.


You can easily specify the maximum allowed size of the file using MaxSizeKB property:

  1. //Register Uploader component to your page   
  2. <?php require_once "phpuploader/include_phpuploader.php" ?>   
  3. <html>   
  4. <body>   
  5.         <form id="form1" method="POST">   
  6.             <?php   
  7.                 // Create Uploader object.   
  8.                 $uploader=new PhpUploader();   
  9.                 // Set a unique name to Uploader   
  10.                 $uploader->Name="myuploader";    
  11.                 // Specify the maximum allowed size of the file using MaxSizeKB property   
  12.                 $uploader->MaxSizeKB=1024000;    
  13.                 // Render Uploader   
  14.                 $uploader->Render();   
  15.             ?>   
  16.         </form>   
  17. </body>   
  18. </html>