jQuery File Upload Cakephp
cakephp, file-upload, jquery
Solution
First of all place all necessary js and css file in webroot directory.
Place them wherever you need like place js file inside webroot/js/jquery_file_upload/ and css inside webroot/css/jquery_file_upload.
Now make one vendor directory called UploadHandler. Inside this directory copy paste UploadHandler.php.
Now you almost done.
now follow below steps.
- In view file copy paste example code which you have downloaded from here. dont forget to give correct path to each js and css files and in form make sure name for file input type is files[ ].
- now created one controller action in which actual magic will happen. copy paste following code and define path as your requirement.
<?php
class ServicePicturesController extends AppController {
var $name = 'ServicePictures';
function upload()
{
$this->layout = "ajax";
App::import('Vendor','UploadHandler',array<'file' => 'UploadHandler/UploadHandler.php'));
$options = array
(
'script_url' => SITE_URL.'service_pictures/upload/',
'upload_dir' => APP.WEBROOT_DIR.DS.'img'.DS.'offer_picture'.DS,
'upload_url' => SITE_URL.'img/offer_picture/',
'max_number_of_files' => 3,
'thumbnail' => array
(
'max_width' => 150,
'max_height' => 150
)
);
$upload_handler = new UploadHandler($options, $initialize = false);
switch ($_SERVER['REQUEST_METHOD'])
{
case 'HEAD':
case 'GET':
$upload_handler->get();
break;
case 'POST':
$upload_handler->post();
break;
case 'DELETE':
$upload_handler->delete();
break;
default:
header('HTTP/1.0 405 Method Not Allowed');
}
exit;
} ?>
I have done it successfully after spending 2 hours and tested it.
you can also integrate database into this.
feel-free to ask more.
Hope this will help you and other programmer brothers.
Download the example code from the link which i mentioned in first step in follow below steps.
Place js and css file as your want but place it inside webroot for cakephp conventions.
Cheers.
Problem
I'm trying to get blueimp's jQuery File Upload working with Cakephp. Everything is great except I seem to be having problems trying to delete something that has been uploaded. I get the error below in the console when I click on delete on particular file. ``` DELETE http://example.com.au/app/webroot/?file=logo%20%285%29.gif 404 (Not Found) jquery.min.js:4XHR finished loading: "http://example.com.au/app/webroot/?file=logo%20%285%29.gif". ``` Is there a reason why this is happening?