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
Related
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.
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.
I'm currently learning how to make a custom module that creates a block with a textfield and upload field. So far so good, only thing is: Drupal doesn't seem to respect my file_validate_size value.
Here's my block_configure code:
$form['file_link'] = array(
'#type' => 'managed_file',
'#title' => t('My upload field'),
'#size' => 60,
'#description' => t('Select a file.'),
'#upload_location' => 'public://',
'#default_value' => variable_get('file_link'),
'#upload_validators' => array('file_validate_extensions' => array(),
'file_validate_size' => array(26214400)
),
);
Most file_validate_size examples that i've found used bytes instead of megabytes. I don't know if this is a must? file_validate_extensions works perfectly though. So what am I doing wrong?
Are you are testing this as an Admin?
file_validate_size seems to be ignored for admins.
btw. if you want the size to be more readable you can write it like
'file_validate_size' => array( 25 * 1024 * 1024 )
this way you can tell at a glance that the limit is 25mb
I've created a formular where the user can upload an image using a file field. In another formular the user is able to change the image he previous uploaded.
So far I was able that the user can upload a new picture or let the field empty and the existing image remains. My question is, how do I show the user in a nice way which file he previously uploaded with the field? Setting a #default_value (#code below) does nothing for me.
//$smallimage = fid of image
$form['smallimage'] = array(
'#type' => 'file',
'#title' => t('Image'),
'#default_value' => $smallimage,
'#description' => t('Upload a file, allowed extensions: jpg, jpeg, png, gif'),
);
Edit:
Switched back to managed files. I've no types to bind my files/images to so I bind them to the first node and the first user. Not a clean solution but it works.
Has anyone a solution/workaround without switching to managed_file?
Thank you in advance
On Drupal FAPI, '#default_value' is not a valid property for type "file", if you want to use the property #default_value in that case you can use
'#type' => 'managed_file'
and your code should look like this,
$form['file'] = array(
'#title' => t('Upload image'),
'#type' => 'managed_file',
'#description' => t('Images must be one of jpg, bmp, gif or png formats.'),
'#default_value' => $fid, //here you need to provide the file id (get it from database or $file_obj->fid).
'#upload_location' => 'public://'
);
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