tailieunhanh - Giải pháp thiết kế web động với PHP - p 27
GENERATING THUMBNAIL IMAGES If you want to delete the original image after the thumbnail has been created, pass true as the second argument to the constructor like this: $upload = new Ps2_ThumbnailUpload('C:/upload_test/', true); The class has the following public methods: • • • setThumbDestination(): This sets the path to the folder where the thumbnail images are to be saved. If you don t call this method, the thumbnails are stored in the same folder as the original images. setThumbSuffix(): Use this to change the suffix inserted into the thumbnail names. The default is _thb. move(): This uploads the original image(s) and generates the thumbnail(s) | GENERATING THUMBNAIL IMAGES If you want to delete the original image after the thumbnail has been created pass true as the second argument to the constructor like this upload new Ps2_ThumbnailUpload C upload_test true The class has the following public methods setThumbDestination This sets the path to the folder where the thumbnail images are to be saved. If you don t call this method the thumbnails are stored in the same folder as the original images. setThumbSuffix Use this to change the suffix inserted into the thumbnail names. The default is _thb. move This uploads the original image s and generates the thumbnail s . By default images that have the same name as an existing one are renamed. To overwrite existing images pass true as an argument to this method. It also inherits the following methods from the parent Ps2_Upload class getMessages Retrieves messages generated by the upload and the thumbnail. getMaxSize Gets the maximum upload size. The default is 50kB. setMaxSize Changes the maximum upload size. The argument should be expressed as the number of bytes permitted. addPermittedTypes This allows you to add other MIME types to the upload. The Ps2_Thumbnail class rejects MIME types that it doesn t recognize but the files are uploaded as normal to the main destination folder. The Ps2_ThumbnailUpload class wasn t designed with mixed uploads in mind so refine the messages generated by the Ps2_Thumbnail class if you want to use the inherited addPermittedTypes method. Because the Ps2_ThumbnailUpload class is dependent on the Ps2_Upload and Ps2_Thumbnail classes you need to upload all three class definition files to your remote web server when using this class on a live website. Chapter summary This has been quite an intense chapter showing not only how to generate thumbnails from larger images but also introducing you to extending an existing class and overriding inherited methods. Designing and extending classes can be confusing at first but it becomes less .
đang nạp các trang xem trước