ApPHP AJAX File Uploader Advanced - Example of Code

Show Plain Text »
  1. <?php
  2.  
  3. ## +---------------------------------------------------------------------------+
  4. ## | 1. Creating & Calling:                                                    |
  5. ## +---------------------------------------------------------------------------+
  6. ## *** define a relative (virtual) path to fileuploader.class.php file
  7. define ('UPLOADER_DIR', '');
  8. ## *** include FileUploader class
  9. require_once(UPLOADER_DIR.'fileuploader.class.php');
  10. ## *** create FileUploader object
  11. $fileUploader = new FileUploader();
  12.  
  13. ## +---------------------------------------------------------------------------+
  14. ## | 2. General Settings:                                                      |
  15. ## +---------------------------------------------------------------------------+
  16. ## *** set unique numeric (integer-valued) identifier for FileUploader
  17. ## *** (if you want to use several independently configured FileUploader objects on single page)
  18. $fileUploader->SetId(1);
  19. ##  *** set style for Uploader
  20. ##  *** 'dark', 'light', 'simple' or your own style
  21. $fileUploader->SetStyle('light');
  22. ## *** set folder where uploaded files are moved to
  23. $fileUploader->SetFolder('uploaded/');
  24. ## *** show progress - false|true (PECL UploadProgress extension must be installed first)
  25. $fileUploader->ShowProgress(true);
  26. ## *** show file icons
  27. $fileUploader->ShowIcons(true);
  28. ## *** show clickable images (true) or buttons (false) for 'upload' and 'remove' commands
  29. $fileUploader->UseYesNoPictures(true);    
  30.  
  31. ## +---------------------------------------------------------------------------+
  32. ## | 3. Set filters:                                                           |
  33. ## +---------------------------------------------------------------------------+
  34. ## *** set allowed extensions for uploaded files
  35. $fileUploader->AddAllowedExtension(array('jpg','gif','png','txt'));
  36. ## *** set maximum allowed size for uploaded files
  37. $fileUploader->SetMaxSize('200kb');
  38. ## *** set the maximum number of files that the user is allowed to upload simultaneously
  39. $fileUploader->SetNumberOfFiles(6);
  40.  
  41. ## +---------------------------------------------------------------------------+
  42. ## | 4. Naming rules:                                                          |
  43. ## +---------------------------------------------------------------------------+
  44. ## *** uploaded files are given random generated names - true|false
  45. $fileUploader->UseRandomNames(false);
  46. ## *** add suffixes like {1},{2} when file names are identical
  47. $fileUploader->UseSuffixes(true);
  48.  
  49. ## +---------------------------------------------------------------------------+
  50. ## | 5. Display FileUploader:                                                  |
  51. ## +---------------------------------------------------------------------------+
  52. $fileUploader->Display();
  53.    
  54. ?>