* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Colin Verot * @package cmf * @subpackage external */ /** * Class upload * * What does it do? * * It manages file uploads for you. In short, it manages the uploaded file, * and allows you to do whatever you want with the file, especially if it * is an image, and as many times as you want. * * It is the ideal class to quickly integrate file upload in your site. * If the file is an image, you can convert, resize, crop it in many ways. * You can also apply filters, add borders, text, watermarks, etc... * That's all you need for a gallery script for instance. Supported formats * are PNG, JPG, GIF and BMP. * * You can also use the class to work on local files, which is especially * useful to use the image manipulation features. * * The class works with PHP 4 and 5, and its error messages can * be localized at will. * * How does it work? * * You instanciate the class with the $_FILES['my_field'] array * where my_field is the field name from your upload form. * The class will check if the original file has been uploaded * to its temporary location (alternatively, you can instanciate * the class with a local filename). * * You can then set a number of processing variables to act on the file. * For instance, you can rename the file, and if it is an image, * convert and resize it in many ways. * You can also set what will the class do if the file already exists. * * Then you call the function {@link process} to actually perform the actions * according to the processing parameters you set above. * It will create new instances of the original file, * so the original file remains the same between each process. * The file will be manipulated, and copied to the given location. * The processing variables will be reseted once it is done. * * You can repeat setting up a new set of processing variables, * and calling {@link process} again as many times as you want. * When you have finished, you can call {@link clean} to delete * the original uploaded file. * * If you don't set any processing parameters and call {@link process} * just after instanciating the class. The uploaded file will be simply * copied to the given location without any alteration or checks. * * Don't forget to add enctype="multipart/form-data" in your form * tag
if you want your form to upload the file. * * How to use it?
* Create a simple HTML file, with a form such as: *
 * 
 *   
 *   
 * 
 * 
* Create a file called upload.php: *
 *  $handle = new upload($_FILES['image_field']);
 *  if ($handle->uploaded) {
 *      $handle->file_new_name_body   = 'image_resized';
 *      $handle->image_resize         = true;
 *      $handle->image_x              = 100;
 *      $handle->image_ratio_y        = true;
 *      $handle->process('/home/user/files/');
 *      if ($handle->processed) {
 *          echo 'image resized';
 *          $handle->clean();
 *      } else {
 *          echo 'error : ' . $handle->error;
 *      }
 *  }
 * 
* * How to process local files?
* Use the class as following, the rest being the same as above: *
 *  $handle = new upload('/home/user/myfile.jpg');
 * 
* * How to set the language?
* Instantiate the class with a second argument being the language code: *
 *  $handle = new upload($_FILES['image_field'], 'fr_FR');
 *  $handle = new upload('/home/user/myfile.jpg', 'fr_FR');
 * 
* * How to output the resulting file or picture directly to the browser?
* Simply call {@link process}() without an argument (or with null as first argument): *
 *  $handle = new upload($_FILES['image_field']);
 *  header('Content-type: ' . $handle->file_src_mime);
 *  echo $handle->Process();
 *  die();
 * 
* Or if you want to force the download of the file: *
 *  $handle = new upload($_FILES['image_field']);
 *  header('Content-type: ' . $handle->file_src_mime);
 *  header("Content-Disposition: attachment; filename=".rawurlencode($handle->file_src_name).";");
 *  echo $handle->Process();
 *  die();
 * 
* * Processing parameters (reseted after each process) * * * The following eight settings can be used to invalidate an upload if the file is an image (note that open_basedir restrictions prevent the use of these settings) * * * The following variables are used only if {@link image_resize} == true * * Use either one of the following * * The following image manipulations require GD2+ * * * * * * * * Values that can be read before calling {@link process}() * * If the file is a supported image type (and open_basedir restrictions allow it) * * * Values that can be read before after {@link process}() * * If the file is a supported image type * * * Requirements * * Most of the image operations require GD. GD2 is greatly recommended * * The class is compatible with PHP 4.3+, and compatible with PHP5 * * Changelog *