image - Symfony sfThumbnail Plugin with 5 Simultaneous Uploads -
I have a product form that users can upload 5 images at once. Everything is working fine with it but I am trying to implement the sfThumbnail plugin so that it can create a thumbnail of each image at the same time. The code below works for Picture 1 but does not do the pictures 2, 3, 4, and 5. I have tried to mess with the code and I can not get it to work with each file individually, it just takes uploaded file for example 2 and it has the same name as 1 picture are given. So when I run it, I end up with 5 uploaded photos, but only 1 thumbnail with the file name of the first picture
I tried duplicating code 5 times and every photo Tried to customize it but I got the same result.
If there is a more efficient way of doing this, please show me it is only available from the plug-in document. Thanks
if ($ this- & gt; modified ()) {$ uploadDir = sfConfig :: find ('sf_upload_dir'); $ Thumbnail = new sfThumbnail (150, 150); $ Thumbnail- & gt; LoadFile (. $ UploadDir '/ car /'. $ This-> getPicture1 ()); $ Thumbnail- & gt; Save ($ UploadDear. / Car / Thumbnail / '. $ This- & gt; Receive Picture 1) ()); }
First delete your function:
($ This-> isModified ()) {$ uploadDir = sfConfig :: find ('sf_upload_dir'); $ Thumbnail = new sfThumbnail (150, 150); $ Thumbnail- & gt; LoadFile (. $ UploadDir '/ car /'. $ This-> getPicture1 ()); $ Thumbnail- & gt; Save ($ UploadDear. / Car / Thumbnail / '. $ This- & gt; Receive Picture 1) ()); }
and include this function in your form class:
Upload secure function process file ($ field, $ filename = null, $ values = Null) {/ $ 1 $ fn = parent :: processUploadedFile ($ field, $ filename, $ values) to move to the name of the Prindo IL file; // $ (= $! = "") {Try {// array multidimensional diverted to tipologie thumb esistent $ thumbnail [] = array ('dir' = & gt; 'ico', 'width' = & gt; 75, 'height' => 75); $ Thumbnail [] = array ('dir' = & gt; 'small', 'width' => 150, 'height' => 150); $ Thumbnail [] = array ('dir' => 'medium', 'width' => 400, 'height' => 400); $ Thumbnail [] = array ('dir' = & gt; 'big', 'width' => 800, 'height' => 800); Forex Currency ($ thumbpame as $ thumbnail) {$ currentFile = sfConfig :: get ('sf_upload_dir'). '/ Destination_folder /'. $ Thumbarm ['arr']. '/' $ Fn; If (is_file ($ currentFile)) unlink ($ currentFile); } Forex ($ thumb as thumbnail $ thumb) {$ thumbnail = new sfThumbnail ($ thumbp [['width'], $ 'thumb' ['height'], true, false); $ Thumbnail- & gt; Load file (sfConfig :: get ('sf_upload_dir'). "/ Destination_folder / original /".$ fn); $ Thumbnail- & gt; Save (sfConfig :: get ('sf_upload_dir'). '/ Destination_folder /' $ ThumbParam ['dir']. /. $ Fn, 'image / jpeg'); }} Hold (Exception $ E) {}} Return $ FN; }
Where:
- $ thumbnail []
The array contains all the folders you need, there are three dimensions, so all the thumbs you need - You
php symfony project: permissions code>
This function takes all your files into your form, and generates as much thumbs as you need
Comments
Post a Comment