unload() CakePHP Uploader Plugin does not seem to work - cakephp

I'm using CakePHP 2.1.1 and Miles Johnson's Uploader Plugin v 3.5.
It's working pretty sweet although I think I have a problem when trying to unload the FileValidation behavior.
I have set up both the behaviors Uploader.Attachment and Uploader.FileValidator (see the bottom of the question).
In the afterSave callback I now need to save the Post again to add a Translated field for a different locale.
When I do save again, this seems to cause en error in the FileValidation behavior. I get the error:
failed to open stream: No such file or directory [APP/Plugin/Uploader/Model/Behavior/FileValidationBehavior.php, line 296]
Somehow the Behavior is looking again for the tmp file.
When I do not define the FileValidation behavior at all, all goes well. So I figured to disable the behavior after it has done it's job during regular save(), right before I go for my second save().
In afterSave($created) I therefore state
$this->Behaviors->unload('FileValidation');
$this->save($data);
The error disappears, but I get 4 warnings in return:
Warning (512): Could not find validation handler maxWidth for file [CORE/Cake/Model/Model.php, line 3155]
Warning (512): Could not find validation handler maxHeight for file [CORE/Cake/Model/Model.php, line 3155]
Warning (512): Could not find validation handler filesize for file [CORE/Cake/Model/Model.php, line 3155]
Warning (512): Could not find validation handler required for file [CORE/Cake/Model/Model.php, line 3155]
I also tried $this->Behaviors->disable('FileValidation') but to no avail.
Is this a bug in the Behavior (not properly unloading itself) or am I not properly handling the unload?
kind regards,
Bart
The behavior setup:
public $actsAs = array('Uploader.Attachment' => array(
'file' => array(
'name' => 'uniqueFilename', // Name of the function to use to format filenames
'baseDir' => APP, // See UploaderComponent::$baseDir
'uploadDir' => 'webroot/img/upload/', // See UploaderComponent::$uploadDir
'dbColumn' => 'uploadPath', // The database column name to save the path to
'importFrom' => '', // Path or URL to import file
'defaultPath' => '', // Default file path if no upload present
'maxNameLength' => 30, // Max file name length
'overwrite' => false, // Overwrite file with same name if it exists
'stopSave' => true, // Stop the model save() if upload fails
'transforms' => array(), // What transformations to do on images: scale, resize, etc
's3' => array(), // Array of Amazon S3 settings
'metaColumns' => array( // Mapping of meta data to database fields
'ext' => 'ext',
'type' => 'type',
'size' => 'size',
'group' => 'group',
'width' => 'width',
'height' => 'height',
'filesize' => 'size',
'name'=>'name'
)
)
),
'Uploader.FileValidation' => array(
'file' => array(
'maxWidth' => array(
'value' => 1000,
'error' => 'Image too wide. Max 1000px'
),
'maxHeight' => array(
'value' => 1000,
'error' => 'Image too high. Max 1000px'
),
'extension' => array(
'value' => array('gif', 'jpg', 'png', 'jpeg'),
'error' => 'Mimetype incorrect',
),
'filesize' => array(
'value' => 1048576,
'error' => 'Filesize too high. Max 1 MB'
)
)
)
);

Not directly related, but are you game to try another file upload plugin? This one might do the trick: http://bakery.cakephp.org/articles/srs2012/2012/03/12/ajaxmultiupload_plugin_for_cake_2_0_x_and_2_1

Not sure if this will fix yours but I found (for some reason I don't know why) this error gets thrown if you don't have debug set to 0 in your Config/core.php

Related

Add value to input file

I want to add a field for my File Uploads to see the diffrence between preview and just normal files.
Right now I canĀ“t see the difference, just these Information. But I need a 'preview' => 1 or something. Maybe there is a simpler way to notice the diffrence.
I am getting this in Cakephp
'name' => 'test.jpg',
'type' => 'image/jpeg',
'tmp_name' => '/tmp/phpqq3nhC',
'error' => (int) 0,
'size' => (int) 3633405

MIME type error

With Cakephp 2.6 I have the following warning:
Can not determine the mimetype.
Error: An Internal Error Has Occurred.
Below is my Model:
'mimeType' => array(
'rule' => array('mimeType', array('image/gif', 'image/png', 'image/jpg', 'image/jpeg')),
'message' => 'Please only upload images (gif, png, jpg).',
'allowEmpty' => FALSE,
),
In php.ini (\xampp\php\php.ini) I uncommented
extension=php_fileinfo.dll
But I still have the same error message.
There is no line number in the error message even if my debug is set to 2. the only error message displaying is :
Can not determine the mimetype.Error: An Internal Error Has Occurred.
for the stack trace, the value of 'Validation::mimeType(array, array)' is
array(
'name' => '2009_Infini-jaune-2.jpg',
'type' => 'image/jpeg',
'tmp_name' => 'C:\xampp\tmp\phpEC6C.tmp',
'error' => (int) 0,
'size' => (int) 186994)
array(
(int) 0 => 'image/png',
(int) 1 => 'image/jpeg'
)`
When enabling or disabling extensions, be sure to restart the web server (or PHP if you are running PHP as a FastCGI instance).
Change the text ;extension=php_fileinfo.dll into extension=php_fileinfo.dll on php.ini
It works for me. Hope it helps you guys. I'm using xampp.
Don't forget to restart the web server after that.

Drupal 7.31 custom file field and it's extensions

I have problem with my custom created field for custom node type. This is field instance configuration:
'attachments' => array(
'field_name' => 'vintranet_talk_attachments',
'label' => t('Attachments'),
'entity_type' => 'node',
'bundle' => 'mynodetypename',
'widget' => array(
'type' => 'file_mfw',
),
'settings' => array(
'max_filesize' => 1024 * 1024 * 10,
'file_directory' => 'my/path',
'file_extensions' => 'jpg,png,gif,pdf,zip,doc,rtf,xdoc,rar,txt',
'description_field' => 1,
),
'display' => array(
'default' => array(
'type' => 'file_table',
),
),
),
After installing my module, I wanted to add new node and add some attachments, but I get this error:
Why I can't upload my *.txt file (same with jpg and others) even if I have this file format in "Allowed file types" list?
Only after editing particular node type field settings from the backend page (just by pressing "save" button) everything works perfect...
The answer is to change value of file_extensions to jpg png gif pdf zip doc rtf xdoc rar txt.

Error Loading Views After Changing Route Value of module.config.php - Zend Framework

This question is regarding Zend Framework application version: 2.1.3. I, the developer, am new to Zend Framework and would greatly value your assistance.
I was making a module for a 'Donor Management System' of a church. The module I am working on is called the 'QueryBuilder'. Previous modules were fine and works great. I use the Zend Helper for Sublime Text and it generated some thing similar for the module.config.php
<?php
/**
*
* #package QueryBuilder
*/
return array(
'controllers' => array(
'invokables' => array(
'QueryBuilder\Controller\QueryBuilder' => 'QueryBuilder\Controller\QueryBuilderController',
),
),
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'querybuilder' => array(
'type' => 'segment',
'options' => array(
'route' => '/querybuilder[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'QueryBuilder\Controller\QueryBuilder',
'action' => 'index',
//'action' => 'search',
//'action' => 'recent',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'querybuilder' => __DIR__ . '/../view',
),
),
);
?>
Determined to have a little bit of fun after making some successful modules, I changed the router as follows.
<?php
/**
*
* #package QueryBuilder
*/
return array(
'controllers' => array(
'invokables' => array(
'QueryBuilder\Controller\QueryBuilder' => 'QueryBuilder\Controller\QueryBuilderController',
),
),
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'querybuilder' => array(
'type' => 'segment',
'options' => array(
'route' => '/query-builder[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'QueryBuilder\Controller\QueryBuilder',
'action' => 'index',
//'action' => 'search',
//'action' => 'recent',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'querybuilder' => __DIR__ . '/../view',
),
),
);
?>
Note: Only the route value was changed from /querybuilder... to /query-builder.... When I tried to access the route http://konnections/query-builder I got some error but I didn't go through it.
Wondering why I wan't to be a hero, I changed the value back to its defaults. And tried to load http://konnections/querybuilder but it also gave an error.
Zend\View\Renderer\PhpRenderer::render: Unable to render template "query-builder/query-builder/index"; resolver could not resolve to a file
No where in the code of the module you could find the words query-builder. So common sense says there can be no way query-builder/query-builder/index needs to be accessed.
Thinking it might be some caching, I looked for it in the entire application folder. Then I restarted Apache, the computer, deleted and made a new Module with the same name QueryBuilder and still the error is there.
Note: This is a plugin that was done nothing with. I only changed the route value thinking it will make the URL look neater.
Here is what I end up with [Image]:
Nope, this is not IE, because I tried in Chrome (which didn't access the query-builder url) as well.
The whole of Zend Folder (the root of the website) has no reference to query-builder. Where does it come from and how can I change it?
Thanks in advance.
from ZF1 series (http://framework.zend.com/manual/1.12/en/zend.controller.basics.html), ZF2 is the same but not found this description on manual.
Case Naming Conventions
Since humans are notoriously inconsistent at maintaining case sensitivity when typing links, Zend Framework actually normalizes path information to lowercase. This, of course, will affect how you name your controller and actions... or refer to them in links.
If you wish to have your controller class or action method name have multiple MixedCasedWords or camelCasedWords, you will need to separate those words on the url with either a '-' or '.' (though you can configure the character used).
As an example, if you were going to the action in FooBarController::bazBatAction(), you'd refer to it on the url as /foo-bar/baz-bat or /foo.bar/baz.bat.
I am Ziyan, the one who asked the question in the first place.
After not finding a solution in Google, I wondered in to making another module and ended up with the same plight. Confused I made a new installation of Zend Framework and made a module with the same name.
Zend\View\Renderer\PhpRenderer::render: Unable to render template "query-builder/query-builder/index"; resolver could not resolve to a file did not go away.
Knowing it is not some thing like reconfiguration, I looked closer.
It seemed to put a dash between every word. I was like Zend is insane! But no, it seems to be splitting the Module name from each upper case letter and adjoining them using a '-' (dash).
In my case QueryBuilder becomes query-builder or plugin named HelloModules would be hello-modules.
So the view manager seems to be looking for ../views/query-builder/query-builder/index.
In my case, ZF Helper for Sublime text needs to look in to the situation. If you could fix the plugin at GitHub it would be great. I will give a try my self.
I couldn't find any proof for my claiming and no time to go through the source codes. Would be glad if some one provide some links.

cakephp - use memcache for sessions

I am quite new to cakephp and I'm having trouble getting it configured to work on my live server. It works fine on my local machine.
I think the problem is that my live server is configured to use Memcache. When I visit the live site I get:
Warning (2): session_start() [function.session-start]: open(=1&retry;_interval=15/sess_mt8tpui04vorqojg7s945e5sf5, O_RDWR) failed: No such file or directory (2) [CORE/Cake/Model/Datasource/CakeSession.php, line 615]
Warning (2): session_write_close() [function.session-write-close]: open(=1&retry;_interval=15/sess_mt8tpui04vorqojg7s945e5sf5, O_RDWR) failed: No such file or directory (2) [CORE/Cake/Controller/Controller.php, line 712]
Warning (2): session_write_close() [function.session-write-close]: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (tcp://127.0.0.1:11211?persistent=1&weight;=1&timeout;=1&retry;_interval=15) [CORE/Cake/Controller/Controller.php, line 712]
So i've tried enabling cake to use memcache by adding the following to app/Config/core.php:
Cache::config('default', array(
'engine' => 'Memcache'
));
But I still get the same error.
The php.ini is configured to use memcache correctly.
Any ideas?
Thanks
Your Cache::config looks incomplete!
It should look like this and This code block will be in app/Config/bootstrap.php
Cache::config('default', array(
'engine' => 'Memcache', //[required]
'duration' => 3600, //[optional]
'probability' => 100, //[optional]
'prefix' => Inflector::slug(APP_DIR) . '_', //[optional] prefix every cache file with this string
'servers' => array(
'127.0.0.1:11211' // localhost, default port 11211
), //[optional]
'persistent' => true, // [optional] set this to false for non-persistent connections
'compress' => false, // [optional] compress data in Memcache (slower, but uses less memory)
));
Also you need to set a session handler http://book.cakephp.org/2.0/en/development/sessions.html#cache-sessions
Mine looks like this, note that I have called "sessiones"
& This code block will be in app/Config/core.php
Configure::write('Session', array(
'defaults' => 'cache',
'handler' => array(
'config' => 'sessiones'
),
'cookie' => 'PHPSESSID',
'timeout' => 3600,
'cookieTimeout' => 0,
'autoRegenerate' => false,
'checkAgent' => true,
'ini' => array(
'session.cookie_secure' => false,
'session.cookie_httponly' => true,
)
));
And then set up the Cache:config for the handler "sessiones"
and This code block will be in app/Config/bootstrap.php
Cache::config('sessiones', array('engine' => 'Memcache','duration'=> 3600,/*'prefix' =>'es',*/ 'servers' => array(array('127.0.0.1:11211'), 'compress' => false));

Resources