webtechnick / cakephp-fileupload-plugin Goto Github PK
View Code? Open in Web Editor NEWCakePHP File Upload Handling Plugin
Home Page: http://www.webtechnick.com
CakePHP File Upload Handling Plugin
Home Page: http://www.webtechnick.com
Could you please add this plugin to Composer?
Take a look at this page in CakePHP book. In essence, in current code, if you have multiple models that use this behavior but with different options, all models will use the options that were passed to model that was last instantiated.
To avoid this problem, $this->options should actually be $this->options[$Model->alias]. Same goes for $this->Uploader I think.
When trying to upload a file i get the following error:
Warning (2): Invalid argument supplied for foreach() [APP/Plugin/file_upload/Controller/Component/FileUploadComponent.php, line 341]
The lines are:
function processAllFiles(){
foreach($this->uploadedFiles as $file){
$this->_setCurrentFile($file);
$this->Uploader->file = $this->options['fileModel'] ? $file[$this->options['fileVar']] : $file;
$this->processFile();
}
}
How to i solve this? Thanks.
Fatal error: Class 'FileUploadSettings' not found in /home/christian/public_html/unlweb/svn/webunl/app/Plugin/FileUpload/Controller/Component/FileUploadComponent.php on line 155
The file exist in config, may be de line:
App::import('Config', 'FileUpload.file_upload_settings');
fail, but i don´t know why?
Hi, I'm trying to use the master branch wht Cake 2.0.6 and get this error: Fatal error: Class 'Uploader' not found in /var/www/html/jobapp/app/Plugin/file_upload/models/behaviors/file_upload.php on line 55
Any help?
When you delete a file it gets removed fine but the corresponding files from the "resized" directory are not deleted...
"Notice (8): Undefined index: filename [CORE/plugins/file_upload/models/behaviors/file_upload.php, line 110]"
I have a Model "Document" with a belongsTo = 'Upload', and when I try to delete any document, I get this error.
The line before, "$data = $Model->read();" only reads the "Document" model and not the related "Upload" model, so thats why there's no filename index.
trying to implement this myself but having trouble.
anyone worked towards it or is it in any future plans?
my resized images are very pixely..
Could you clarify LICENSE?
Error when using FileUpload 6.1.1 with CakePHP 2.2.1
Strict (2048): Declaration of FileUploadBehavior::setUp() should be compatible with ModelBehavior::setup(Model $model, $config = Array) [APP\Plugin\FileUpload\Model\Behavior\FileUploadBehavior.php, line 124]
Strict (2048): Declaration of FileUploadBehavior::beforeValidate() should be compatible with ModelBehavior::beforeValidate(Model $model) [APP\Plugin\FileUpload\Model\Behavior\FileUploadBehavior.php, line 124]
Strict (2048): Declaration of FileUploadBehavior::beforeSave() should be compatible with ModelBehavior::beforeSave(Model $model) [APP\Plugin\FileUpload\Model\Behavior\FileUploadBehavior.php, line 124]
Strict (2048): Declaration of FileUploadBehavior::beforeDelete() should be compatible with ModelBehavior::beforeDelete(Model $model, $cascade = true) [APP\Plugin\FileUpload\Model\Behavior\FileUploadBehavior.php, line 124]
found the solution in here - http://stackoverflow.com/questions/11678249/meio-upload-strict-erros
I receive this error when I try to navigate to ../admin/uploads
Fatal error: Cannot redeclare class FileUploadSettings in C:\xampp\htdocs\zau\app\plugins\file_upload\config\file_upload_settings.php on line 2
I'm using behavior configuration in an existing controller (apartments_controller), the goal is to add a picture to each entry. FileUpload plugin is also used in another controller (uploads_controller), where it works fine. Unfortunately, when I use the FileUpload plugin in 'apartments', it stores the file info to the 'uploads' table.
Am I missing something, or this can't be done?
Hi, I try to migrate the plugin to cakephp 2.0.3 but I have a problem:
Fatal error: Class 'FileUploadSettings' not found in /home/christian/public_html/unlweb/svn/webunl/app/Plugin/FileUpload/Controller/Component/FileUploadComponent.php on line 154
In line 154 of FileUploadComponenet it is this line:
$FileUploadSettings = new FileUploadSettings();
and I add in FindUploadComponent file App::import('FileUpload', 'FileUploadSettings'); in order the class was available.. what is the error?
I’ve a model that I’ve added the file upload plugin to as a behavior. My model is set up as follows:
<?php
class Promoter extends AppModel {
public $name = 'Promoter';
public $actsAs = array(
'Containable',
'FileUpload.FileUpload' => array(
'allowedTypes' => array(
'gif' => array(
'image/gif'
),
'jpg' => array(
'image/jpeg',
'image/pjpeg'
),
'png' => array(
'image/png'
)
),
'fields' => array(
'name' => 'image_filename',
'type' => 'image_type',
'size' => 'image_size'
),
'fileNameFunction' => 'sanitizeFileName',
'required' => false
)
);
public function sanitizeFileName($filename) {
$imagesDir = 'promoters';
if (!is_dir($imagesDir)) {
mkdir($imagesDir);
chmod($imagesDir, 0755);
}
$extension = pathinfo($filename, PATHINFO_EXTENSION);
return $imagesDir . DS . $this->data[$this->alias]['id'] . '.' . $extension;
}
}
As you can see, required
is set to false
. The Promoter model is saved successfully if I also include an image for upload (the values are set in the database row, and the actual image is uploaded to the file system); however, if I don’t select an image to upload, then the database record is not updated despite getting a flash message saying record has been updated.
Any one able to see what the problem is? Have I configured something incorrectly, or is this just because this is the in-development branch and it’s not been addressed yet?
I'm having a problem with getting the plugin to store the filename in the database. It uploads the file just fine, but never saves the filename. My table looks like this:
CREATE TABLE crochet_items_files
(
id
int(11) unsigned NOT NULL AUTO_INCREMENT,
crochet_item_id
int(11) NOT NULL,
title
varchar(255) NOT NULL,
filename
varchar(255) NOT NULL,
mimetype
varchar(255) DEFAULT NULL,
filesize
int(11) DEFAULT NULL,
created
datetime DEFAULT NULL,
modified
datetime DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;
and my model actsAs statement looks like this:
var $actsAs = array(
'FileUpload.FileUpload' => array(
'uploadDir' => 'uploads/crochet_item/files',
'fileVar' => 'filename',
'allowedTypes' => array(
'jpg' => array('image/jpeg', 'image/pjpeg'),
'jpeg' => array('image/jpeg', 'image/pjpeg'),
'gif' => array('image/gif'),
'png' => array('image/png'),
'txt' => array('text/plain'),
'pdf' => array('application/pdf'),
'doc' => array('application/msword')
),
'fields' => array('name' => 'filename', 'type' => 'mimetype', 'size' => 'filesize'),
'required' => false,
'unique' => true,
'fileNameFunction' => false
)
);
By the way, will FileUpload also save the directory path? I didn't see that among the options.
so if i have a model Books and i want have an image for each book, without usign a sepreate table to store the book images
Array
(
[Book] => Array
(
[id] => 348
[name] => Some Book Name
[file] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)
)
)
if no file has been uploaded (either because none was chosen or one already exists) then it unsets the entire model rather than just the [file] portion
this patch introduces a allowEmpty option which defaults to false, but if true will only unset the [file] portion allowing any changes to the [name] to be saved
diff --git a/config/file_upload_settings.php b/config/file_upload_settings.php
old mode 100644
new mode 100755
index 2b08d42..ea2cc8f
--- a/config/file_upload_settings.php
+++ b/config/file_upload_settings.php
@@ -187,7 +187,14 @@ class FileUploadSettings {
\* 'fileNameFunction' => 'md5'
\* 'fileNameFunction' => 'crc32'
*/
- 'fileNameFunction' => false
- 'fileNameFunction' => false,
+
- /**
- \* To allow Model to be saved without the file fields if no file is uploaded.
- *
- \* For use when using FileUpload directly on an existing Model.
- */
- ```
'allowEmpty' => false
```
);
}
diff --git a/models/behaviors/file_upload.php b/models/behaviors/file_upload.php
old mode 100644
new mode 100755
index 040b5d1..21c6418
--- a/models/behaviors/file_upload.php
+++ b/models/behaviors/file_upload.php
@@ -76,7 +76,12 @@ class FileUploadBehavior extends ModelBehavior {
unset($Model->data[$Model->alias][$this->options[$Model->alias]['fileVar']]);
}
else {
- unset($Model->data[$Model->alias]);
- if ($this->options[$Model->alias]['allowEmpty']) {
- //unset only the file portion of the model so that the rest fo the model's data will be saved
- unset($Model->data[$Model->alias]['file']);
- } else {
- unset($Model->data[$Model->alias]);
- }
}
}
return $Model->beforeSave();
I'm using the fileNameFunction feature to generate a SHA-1 hash of the file name, but the problem is that when you upload a file for the first time and the hash generates a unique value some how the extension of the file is lost and the file which is saved has no extension.
The problem seems to be at line number 90 in the "uploader.php" file under the "vendors" folder.
return $fileName . $this->_ext();
instead of
return $fileName;
I'm trying to use the FileUpload
plugin in my CakePHP (1.3) app. I have two models: PendingContract
and PendingContractFile
. A PendingContract
can have many PendingContractFile
. When saving a new PendingContract
, I'd also like to save the uploaded PendingContractFile
, however, my save method fails because PendingContract
does not yet have an ID, and that is used as the foreign key in my PendingContractFile
.
For clarity, here are my models:
<?php
class PendingContract extends AppModel {
var $name = 'PendingContract';
var $belongsTo = array(
'Supplier'
);
var $hasMany = array(
'PendingContractFile'
);
}
<?php
class PendingContractFile extends AppModel {
var $name = 'PendingContractFile';
var $belongsTo = array(
'PendingContract' => array(
'className' => 'PendingContract',
'foreignKey' => 'pending_contract_id'
),
'Author' => array(
'className' => 'User',
'foreignKey' => 'author_id'
)
);
}
And here is my controller method where I'm saving my PendingContract
:
<?php
class PendingContractsController extends AppController {
function add() {
if (!empty($this->data)) {
if ($this->FileUpload->success) {
$this->Session->setFlash('Pending contract successfully created.');
$this->redirect(array('action' => 'index'));
}
else {
$this->Session->setFlash($this->FileUpload->showErrors());
}
}
}
}
Currently the error I'm getting is:
1452: Cannot add or update a child row: a foreign key constraint fails (pending_contract_files, CONSTRAINT pending_contract_files_ibfk_1 FOREIGN KEY (pending_contract_id) REFERENCES pending_contracts (id) ON DELETE CASCADE ON UPDATE CASCADE)
How can I use the FileUpload
plugin so that it attaches the uploaded file with my new PendingContract
record?
When I enable debug, I keep getting this warning
```
But the plugin is uploading the file and saving the data in the model.
The thing that looks strange to me, is that the warning is beig generated in the component even when I'm only using behaviours.
But if I remove the plugin for the list of components in `app_controller.php`, I receive the following error: `Cannot redeclare class FileUploadSettings`
So a quick question, becuase I could not find the answer in the docs.
If I am just using behaviours, is it required to list the plugins in the components array of `app_controller.php`?
```
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.