A full-blown AJAX file uploader plugin for CakePHP 2.1. Using this, you can add multiple file upload behaviour to any or all of your models without having to modify the database or schema.
You can click on the Upload File button, or drag-and-drop files into it. You can upload multiple files at a time without having to click on any button, and it shows you a nice progress notification during uploads.
You can either download the ZIP file:
https://github.com/traedamatic/CakeAjaxUploader/zipball/master
or checkout the code
git clone git://github.com/traedamatic/CakeAjaxUploader.git
Unzip or move the contents of this to "Plugin/CakeAjaxUploader" under the app root.
Open Config/bootstrap.php and add this line:
CakePlugin::load(array(
'CakeAjaxUploader' => array(
"bootstrap" => true,
"routes" => true
)
)
);
This will allow the plugin to load all the files that it needs.
Make sure to create the correct files upload directory if it doesn't exist already:
cd cake-app-root mkdir webroot/files chmod -R 777 webroot/files
The default upload directory is "files" under /webroot - but this can be changed (see FAQ below.)
You don't have to give it a 777 permission - just make sure the web server user can write to this directory.
A complete listing of all files in your upload path(including delete link) under:
http://www.yourserver.com/filelisting
Add to Controller/AppController.php for use in all controllers, or in just your specific controller where you will use it as below:
var $helpers = array('AjaxMultiUpload.Upload');
Add this to your View/Companies/view.ctp:
echo $this->Upload->view("path/to/my/upload/folder");
and this to your View/Companies/edit.ctp:
echo $this->Upload->edit("path/to/my/upload/folder");
Nope. :) Just drop this plugin in the right Plugin/ directory and add the code to the controller and views. Make sure the "files" directory under webroot is writable, otherwise uploads will fail.
No tables/database changes are needed since the plugin uses a directory structure based on the model name and id to save the appropriate files for the model.
The default upload file size limit is set to a conservative 2 MB to make sure it works on all (including shared) hosting. To change this:
- Open up Plugin/AjaxMultipUpload/Config/bootstrap.php and change the "AMU.filesizeMB" setting to whatever size in MB you like.
- Make sure to also change the upload size setting ( upload_max_filesize and post_max_size) in your PHP settings ( php.ini) and reboot the web server!
Are you stuck to the "files" directory under webroot? Nope.
Open up Config/bootstrap.php under the Plugin/AjaxMultiUpload directory and change the "AMU.directory" setting.
The directory will live under the app webroot directory - this is as per CakePHP conventions.
Coming soon.
- Rewrite the upload valums PHP script
This uses the Ajax Upload script from: http://valums.com/ajax-upload/ and file icons from: http://www.splitbrain.org/projects/file_icons
If you find this plugin useful, please consider a donation to Shen Yun Performing Arts to support traditional and historic Chinese culture.
or