Changelogs: Uploader v4.0.0

A new version of Uploader has been released, version 4.0.0. Please download the new tag or view the documentation. If you have any questions, be sure to send me an email or comment on this post. If you run into any problems, be sure to report an issue on the Github repository.

Version: 4.0.0
Tested On: PHP 5.4
Requires: PHP 5.3
Commit Hash: f4d115ff504abdb8b1c7e508ae530300ef53409c
Changes:

  • Updated to use Composer extensively
  • Updated to use Transit and AWS SDK internally
  • Uploader and S3 classes have been removed (uploading is done purely in the model layer)
  • Transformations can be applied to the original file or used to create new files
  • Transformations now support the following options: nameCallback, append, prepend, uploadDir, finalPath, overwrite and self
  • Added Model::deleteImages($id) to delete uploaded files and not the record
  • Added automatic file deletion when a record is deleted, or a path is being overwritten with a record update
  • Added built in support for file uploading and importing (local, remote or stream)
  • Added rollback file deletion if the upload process fails
  • Added Model::beforeTransport() callback
  • Added logging for critical errors
  • Added AWS S3 and Glacier transport support
  • Added type and mimeType validation rules
  • Improved the error handling
  • Improved file renaming and moving
  • Removed config and mime type mapping
  • Removed Test and Vendor files
  • Option name was renamed to nameCallback
  • Option importFrom was removed as importing is built in
  • Option s3 was replaced with transport
  • Option metaColumns had keys renamed
  • Options baseDir and uploadDir were replaced with tempDir, uploadDir and finalPath
  • Options maxNameLength and saveAsFilename were removed
  • View the updated documentation for help

32 Comments

  • Miles, thanks for your input, I have it working correctly now! =)
    For those wondering how it is done, just point the autoload.php file to load from the right location:
    from:
    require_once dirname(__DIR__) . '/Vendor/autoload.php';

    to (for me):
    require_once dirname(__DIR__) . '/Plugin/Uploader/vendor/autoload.php';

    Miles, if I am misleading someone, please correct me.
    Thanks again for your help!
    SecBin
    • Sorry but that is wrong, do not use this approach. You are not supposed to run composer from within the Uploader plugin, you are supposed to install and use composer within the app/ folder.

      http://milesj.me/blog/read/using-composer-in-cakephp

      Dependencies are then installed into the Vendor and Plugin folders.
      • You are absolutely right, probably I had the issue because of me downloading it from GitHub and overlooking the fact that we should create the 'composer.json' file in the app folder.
        So, to all those people new or not so familiar to Composer, use it and DO NOT download a single line of code from GitHub in order to have this great plugin working. Really, if you already have composer running. It should take less than 5 minutes to install.
        Miles, thanks for the input. I have it running correctly this time!
        SecBin
  • Tnx for your works.
    I installed uploader plugin but i have a following problem and what i missing or fault.
    Class 'Transit\Transit' not found
    • Read the docs: http://milesj.me/code/cakephp/uploader#installation
      • Hi Miles,

        I used Composer to install the dependencies, it created the "vendor" folder and inside it has created 2 folders (composer and mjohnson), and 1 file (autoload.php). Of course, jmohnson has a "transit" folder and so on..

        I have seen the Installation instructions more than 20 times now, and looked all over the internet and popular help sites. but I am having the same error:

        Error: Class 'Transit\Transit' not found 
        Line: 234


        I have seen this a couple people with the same problem here. But no pointers.

        Do you think you could let us know what we are doing wrong? Just a simple pointer will be greatly appreciated.

        Thanks in advance!

        SecBin
        SecBin
        • Like I mentioned in the previous comment. It's in the installation docs, you need to enable the autoloader at the top of core.php.

          If that doesn't work, then you'll have to debug the autoloader.
  • First of all, a very helpful plug in. However, I want to use it with JS helper in CakePHP. In your documentation, there is only a small description explaining about uploading using AJAX, and I don't quite get it. Would you mind giving me an example of using your plug in with AJAX? That would be very much appreciated. Thanks in advance.
  • Great Plug-in but I still messed around with some kind of bug I used newest release of uploader, I'm currently test some files for upload, but when files are uploaded it damages and renames all the extensions to .txt, so my question is: Is any way to fix this and upload properly the files, any special configuration in php.ini or so?

    Thanks.
    x010100x
  • Hi Everybody ,

    How to use transit script, where to copy the folder etc as it give me following error .

    Class 'Transit\Transit' not found
    Deepak Kumar ⋅
  • First, thank you for this great plugin.

    Second, can you give us some tips about video uploads? File types, size limit...I saw only examples with images.

    Best wishes.
  • Nevermind, I figured out that I need to enable the php_finfo extension from within php.ini.

    Thanks,

    Matt
    Matthew
  • Hi Miles,

    I've installed your plugin, but when I try and upload an image I get the following error:

    Error: Call to undefined function Transit\finfo_open()
    File: C:\Users\matthew.a.croxon\Documents\Coding\ArtPortfolio\app\Vendor\mjohnson\transit\src\Transit\File.php
    Line: 338

    Any ideas?

    Thanks,

    Matt
    Matthew
  • I download cake v2.2.5 and uploader v4.0.6, but I can't not run plugin in my project because of error: Uploader.UploaderComponent could not be found!. So how can I fix it? Thanks
    hoangminhtoan
  • I would like to specify specific crop locations so that I can allow a user to select how they want the image to be cropped. I don't have a problem getting that information from the user but I don't think your plugin provides a way to specify coordinates as to where to start the crop from.

    If it does, that would be great and I would be glad to hear about it.

    thanks for your hard work to make Cake a piece of cake.

    Michael
    Michael
  • hi miles i am new to cake php. i can't understand how to use your plugin . Can u guide me mile please....
    sivaraj
  • Miles, I want to use your plugin to upload multiple file in one from, can you give me an idea?
    cyrillusekana
  • @Francois - That is most likely the case. Could you please submit a bug report?
  • When using the S3 transport, metadata fails to save because the original file is deleted when transported.

    Or maybe I'm missing something.
    Francois Richard
  • Miles, thank you for your help but I solved the problem. I forgot to put
    array('type' => 'file')
    in form creation, in view.
  • Hi,
    Yes. I've rechecked my folders and are writable (chmod 777).
  • Hello again,

    Thank you for the fast reply.
    I've setted up an absolute path to the folder for uploaded files like in the exmples you pointed me to and I still have the exact same problems...
  • @Kevin - Sorry the docs are backwards. Switch type and mimeType, that should fix it.
  • Thank you for writing this plugin, I'm fairly new to web development and this has been a pretty straightforward plugin to get working.

    At the moment I'm running into one last problem that I can't seem to figure out, which is mimeType validation. Without it it everything is working fine, however with the following code in place in the relevant model:

    
    'Uploader.FileValidation' => array(
    		'image' => array(
    			'extension' => array('gif', 'jpg', 'png', 'jpeg'),
    			'required' => array(
    				'value' => true,
    				'error' => 'File required'
    			),
    			'mimeType' => array("image/jpg", "image/jpeg")
    		)
    


    Results in the error: "Sub-type image/jpg does not exist". The code is straight from the example validation with "image/gif" changed to the two jpeg mime types. Any thoughts?
  • I got it working, at last!
    Now after starting to work with it I've noticed it will properly overwrite the files if it's of the same extension, but if the extensions are different from each other the older files will still exist.

    For example, I tried uploading a cover to a game in my app. It automatically renamed the cover by the primary key it has in my DB, being 10, so the file was renamed to 10.jpg. Now I edited the game and uploaded a .png image which was uploaded as 10.png, but the .jpg still exists.

    Now I can probably hackfix this in the beforeUpload hook something like this:
    // Delete older files
    $files = glob('./img/uploads/games/cover-'.$this->Game->id.'-*');
    foreach($files as $file) {
    	unlink($file);
    }
    


    But how neat is this?
  • Hi,

    I've been looking for a oportunity to upload a file with cakephp 2.1 and have found this page here with google.
    I'm a really noob in PHP and CakePHP so unfortunately I really don't know how to use this plugin.
    I've programmed a webapp with CakePHP 2.x and need the upload function. The webapp is installed on a webserver where I can't use shell or anything like this (command line etc.).
    So I don't really know how to install this plugin because I need the composer and really don't know how to install the composer without comand line etc.
    Can somebody please help me and give me a good guide through the installation of this plugin?

    Thnx
  • Hi,

    I've been looking for a oportunity to upload a file with cakephp 2.1 and have found this page here with google.
    I'm a really noob in PHP and CakePHP so unfortunately I really don't know how to use this plugin.
    I've programmed a webapp with CakePHP 2.x and need the upload function. The webapp is installed on a webserver where I can't use shell or anything like this (command line etc.).
    So I don't really know how to install this plugin because I need the composer and really don't know how to install the composer without comand line etc.
    Can somebody please help me and give me a good guide through the installation of this plugin?

    Thnx
  • @Melvin - You need to include Composers autoloader.

    http://milesj.me/blog/read/using-composer-in-cakephp
  • @Miles - I have installed it with Composer, not sure if I did it correctly though.. I browsed to my app folder with the command line and executed: composer install

    This gave me the following results:
    - Installing composer/installers (v1.0.0)
        Downloading: 100%
      - Installing symfony/event-dispatcher (v2.1.6)
        Downloading: 100%
      - Installing guzzle/guzzle (v3.0.7)
        Downloading: 100%
      - Installing aws/aws-sdk-php (2.0.3)
        Downloading: 100%
      - Installing mjohnson/transit (1.0.0)
        Downloading: 100%


    This created a 'cake-uploader-4.0.0' folder within Plugin/Uploader and also a 'vendor' folder in which all of the dependencies were installed. So some things were downloaded but still, this doesn't make the plugin functional. While it now loads the AttachmentBehavior with the code snippet you supplied, it currently screams it cannot find the Transit folder.

    Class 'Transit\Transit' not found


    Should I manually place these files somewhere? Or is this supposed to work automagically?

    Thanks a bunch for your time.
  • Thanks fot this great CakePHP plugin! Without it, uploading in CakePHP would be a hassle.

    Mike
  • @Melvin - To answer your first question, you need to import the AttachmentBehavior into scope. CakePHP doesn't have autoloading.

    App::uses('AttachmentBehavior', 'Uploader.Model/Behavior');


    Or you can just use the string "crop" instead of the constant (it even says that in the PHP comment).

    And another problem, you should be using Composer when installing the plugin -- not manually downloading the files. Composer How To
  • Heya,

    I've tried using the 4.0.0 version of the Uploader plugin. I downloaded the files, put them in Plugin/Uploader and in my bootstrap.php is the CakePlugin::loadAll() so I assume it should be loaded.

    Though when I create an $actsAs configuration it gives me the following error:
    Error: Class 'AttachmentBehavior' not found


    My code looks like this:
    public $actsAs = array(
    		'Uploader.Attachment' => array(
    			'box_image' => array(
    				'overwrite' => true,
    				'uploadDir' => UPLOAD_DIR,
    				'finalPath' => 'img/uploads/games',
    				'transforms' => array(
    					'imageIndex' => array(
    						'method' => AttachmentBehavior::CROP, // or crop
    						'location' => 'top',
    						'append' => '-thumb-index',
    						'width' => 124,
    						'height' => 155
    					),
    					'imageView' => array(
    						'method' => 'resize',
    						'append' => '-thumb-view',
    						'width' => 215,
    						'aspect' => false
    					)
    				)
    			)
    		)
    	)



    Any ideas as to why it is not functioning?