Can't upload image using Miles Johnson Uploader - cakephp

I'm developing an application, where in I've created a products table that has following attributes.
{id, image, warranty-image, created, modified}
I'm using miles johnson 4.3.1 uploader for uploading images. So I've written $actsAs in Product model as follows.
public $actsAs = array(
'Uploader.Attachment' => array(
'image' => array(
'overwrite' => true,
'uploadDir' => 'img/products',
'finalPath' => '',
'dbColumn' => 'image',
'transforms' => array(
'imageLarge' => array(
'nameCallback' => 'transformNameCallback',
'method' => 'resize',
'prepend' => 'large_',
'width' => 750,
'height' => 100,
'aspect' => false
)
),
'warranty_image' => array(
'overwrite' => true,
'uploadDir' => 'img/products',
'finalPath' => '',
'dbColumn' => 'warranty_image',
'transforms' => array(
'warranty_imageSmall' => array(
'nameCallback' => 'transformNameCallback',
'method' => 'resize',
'prepend' => 'small_',
'width' => 150,
'height' => 96,
'aspect' => false
)
)
)
),
'Uploader.FileValidation' => array(
'image' => array(
'required' => true,
'extension' => array('gif', 'jpg', 'png', 'jpeg'),
'type' => array('image'),
'minWidth' => 100,
'minHeight' => 100,
'filesize' => 5242880
),
'warranty_image' => array(
'required' => true,
'extension' => array('gif', 'jpg', 'png', 'jpeg'),
'type' => 'image',
'minWidth' => 100,
'minHeight' => 96,
'filesize' => 5242880
)
)
);
public function transformNameCallback($name, $file) {
return $this->getUploadedFile()->name();
}
In add view I've written file inputs as follows.
echo $this->Form->create('Product', array('enctype' => 'multipart/form-data'));
echo $this->Form->file('image');
echo $this->Form->file('warranty_image');
echo $this->Form->end();
This uploader just uploading only image image but not warranty_image image. Please help me to get the solution. The work would be more appreciated.

I would recommend https://github.com/josegonzalez/cakephp-upload
This works very similarly to how you are looking and actually does work correctly.

Use HTML input tag in view or CakePHP Form Helper Input tag.
echo $this->Form->input('image', array('type' => 'file', 'required' => false, 'label' => 'Select the File to Upload'));
echo $this->Form->input('warranty_image', array('type' => 'file', 'required' => false, 'label' => 'Select the File to Upload'));

Your database table is using "warranty-image" as the field.
But your PHP code is using "warranty_image".
Note the "-" instead of "_"

Related

How do I add publish dates to uploaded files in Typo3?

I am currently maintaining a client's existing Typo3 6.1 site and one of the things they would like to add to their site is the possibility of applying publish and expiration dates on uploaded files, in the same way such dates can be applied on Typo3 pages.
I did some research on the matter to see if something like this had already been done before. I tried looking for existing Typo3 extensions on Google and on the official Typo3 extensions repository that would add this functionality, but nothing like this seems to exist. I also tried to find ways of doing it myself, still without any results.
What would be the best approach to add this functionality to a Typo3 6.1 website?
EDIT
After some investigating, I noticed another extension was already hooked up with the TCEForm of the file editing page: http://i.stack.imgur.com/up7mO.png
In this screenshot, you can see I managed to add the start and end datetime fields as the first two fields in the form ("Date de publication" and "Date d'expiration"). I currently have the following configuration in my ext_table.php:
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
$_EXTKEY, 'Documents', 'Documents'
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'Documents');
\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('sys_file');
$newFileColumns = array(
'date_publication' => array(
'exclude' => 0,
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.date_publication',
'config' => array(
'type' => 'input',
'size' => 13,
'max' => 20,
'eval' => 'datetime',
'checkbox' => 0,
'default' => 0,
'range' => array(
'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
),
),
),
'date_expiration' => array(
'exclude' => 0,
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.date_expiration',
'config' => array(
'type' => 'input',
'size' => 13,
'max' => 20,
'eval' => 'datetime',
'checkbox' => 0,
'default' => 0,
'range' => array(
'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
),
),
),
'desactive' => array(
'exclude' => 1,
'config' => array(
'type' => 'passthrough'
)
),
'isbn' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.isbn',
'config' => array(
'type' => 'input',
'size' => 50,
'eval' => 'trim'
),
),
'auteurs_internes' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.auteurs_internes',
'config' => array(
'type' => 'select',
'foreign_table' => 'fe_users',
'MM' => 'tx_documents_document_auteur_mm',
'size' => 5,
'maxitems' => 10,
'minitems' => 0,
'wizards' => array(
'suggest' => array(
'type' => 'suggest',
'default' => array(
'searchWholePhrase' => 1
),
),
),
),
),
'auteurs_externes' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.auteurs_externes',
'config' => array(
'type' => 'input',
'size' => 50,
'eval' => 'trim'
),
),
'responsable' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.responsable',
'config' => array(
'type' => 'group',
'internal_type' => 'db',
'allowed' => 'tx_common_domain_model_unitelogique',
'size' => 1,
'maxitems' => 1,
'minitems' => 0,
'wizards' => array(
'suggest' => array(
'type' => 'suggest',
'default' => array(
'searchWholePhrase' => 1
),
),
),
),
),
'type_document' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.type_document',
'config' => array(
'type' => 'select',
'foreign_table' => 'sys_category',
'foreign_table_where' => ' AND sys_category.tx_common_type = "type_document" ORDER BY sys_category.title ASC',
'maxitems' => 1,
'minitems' => 1,
'renderMode' => 'tree',
'treeConfig' => array(
'parentField' => 'parent',
),
),
),
'public_cible' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.public_cible',
'config' => array(
'type' => 'select',
'foreign_table' => 'sys_category',
'MM' => 'tx_documents_document_publiccible_mm',
'foreign_table_where' => ' AND sys_category.tx_common_type = "public_cible_document" ORDER BY sys_category.title ASC',
'maxitems' => 100,
'minitems' => 0,
'renderMode' => 'tree',
'treeConfig' => array(
'parentField' => 'parent',
),
),
),
'important' => array(
'exclude' => 1,
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.important',
'config' => array(
'type' => 'check',
),
),
'nouveau' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.nouveau',
'config' => array(
'type' => 'input',
'eval' => 'date'
),
),
'misajour' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.misajour',
'config' => array(
'type' => 'check',
),
),
'no_magistra' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.no_magistra',
'config' => array(
'type' => 'input',
'size' => 50,
'eval' => 'trim'
),
),
'centre_documentation' => array(
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.centre_documentation',
'config' => array(
'type' => 'check',
),
),
'image' => array(
'exclude' => 0,
'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.image',
'config' => array(
'type' => 'group',
'internal_type' => 'file',
'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
'minitems' => 0,
'maxitems' => 1,
'size' => 1,
'show_thumbs' => 1,
'uploadfolder' => 'uploads/pics',
'disable_controls' => 'list',
),
),
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file', $newFileColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sys_file', '--div--;LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.tab, date_publication, date_expiration, isbn, auteurs_internes, auteurs_externes, responsable, type_document, public_cible, important, nouveau, no_magistra, centre_documentation, image');
// Edit of existing fields
\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('sys_file');
$TCA['sys_file']['columns']['title']['config']['placeholder'] = '';
$TCA['sys_file']['columns']['title']['config']['eval'] = 'required';
$TCA['sys_file']['columns']['title']['config']['size'] = '50';
$TCA['sys_file']['columns']['description']['config']['wizards'] = array(
'RTE' => array(
'icon' => 'wizard_rte2.gif',
'notNewRecords' => 1,
'RTEonly' => 1,
'script' => 'wizard_rte.php',
'title' => 'LLL:EXT:cms/locallang_ttc.xlf:bodytext.W.RTE',
'type' => 'script'
)
);
$TCA['sys_file']['columns']['description']['defaultExtras'] = 'richtext:rte_transform[flag=rte_enabled|mode=ts]';
// Add category types
\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('sys_category');
$TCA['sys_category']['columns']['tx_common_type']['config']['items'][] = array('LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:category.type.type_document', 'type_document');
$TCA['sys_category']['columns']['tx_common_type']['config']['items'][] = array('LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:category.type.public_cible_document', 'public_cible_document');
?>
However, defining the columns as start and end access dates with
$GLOBALS['TCA']['sys_file']['ctrl']['enablecolumns']['starttime'] = 'tx_myext_starttime';
$GLOBALS['TCA']['sys_file']['ctrl']['enablecolumns']['endtime'] = 'tx_myext_starttime';
as suggested in the answers makes the file list show an error instead of loading a list of files. Instead, I tried using the $TCA variable to define them. The error page shown by Typo3 is not shown anymore using this, but the editing page still can't be rendered successfully.
The $TCA configuration I added:
$TCA['sys_file'] = array(
'ctrl' => array(
'label' => 'title',
'label_alt' => 'name,description,alternative,identifier,uid',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'versioningWS' => 2,
'versioning_followPages' => TRUE,
'origUid' => 't3_origuid',
'enablecolumns' => array(
'disabled' => 'desactive',
'starttime' => 'date_publication',
'endtime' => 'date_expiration',
)
)
);
The following image shows what happens with this $TCA configuration added while trying to edit a file: http://i.stack.imgur.com/8VaCD.png
The TCEForm is simply not rendered and I don't know why. I'm not sure if my configuration in ext_tables.php contains a bad configuration (especially in the $TCA config I added) or if the problem comes from another file in the extension.
What can be causing this error and how can I fix it?
FAL (File Abstraction Layer) does not have a starttime and endtime field.
But since the sys_file related tables (like sys_file_reference) can be extended by your own extension and TCA offers you the starttime/endtime functionality by default my biggest guess will be that this can be accomplished with some modifications in the TCA.
Here a quick kickstart of how you can try to extend sys_file with the starttime and endtime fields.
ext_emconf.php
$EM_CONF[$_EXTKEY] = array (
// more stuff here in between
'constraints' => array (
'depends' => array (
'filelist' => '6.1.0-6.1.99',
),
),
);
ext_tables.sql
#
# Table structure for table 'sys_file'
#
CREATE TABLE sys_file (
tx_myext_starttime int(11) unsigned DEFAULT '0' NOT NULL,
tx_myext_endtime int(11) unsigned DEFAULT '0' NOT NULL,
)
ext_tables.php
<?php
if (!defined ('TYPO3_MODE')) {
die ('Access denied.');
}
$tempColumns = array();
$tempColumns['tx_myext_starttime'] = array(
'exclude' => 1,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.starttime',
'config' => array(
'type' => 'input',
'size' => 13,
'max' => 20,
'eval' => 'datetime',
'checkbox' => 0,
'default' => 0,
'range' => array(
'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
),
),
);
$tempColumns['tx_myext_endtime'] = array(
'exclude' => 1,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.endtime',
'config' => array(
'type' => 'input',
'size' => 13,
'max' => 20,
'eval' => 'datetime',
'checkbox' => 0,
'default' => 0,
'range' => array(
'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
),
),
);
$GLOBALS['TCA']['sys_file']['ctrl']['enablecolumns']['starttime'] = 'tx_myext_starttime';
$GLOBALS['TCA']['sys_file']['ctrl']['enablecolumns']['endtime'] = 'tx_myext_starttime';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file', $tempColumns, 1);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sys_file', '--div--;LLL:EXT:cms/locallang_ttc.xlf:tabs.access, tx_myext_starttime, tx_myext_endtime');
unset($tempColumns);
I don't know if the FAL persistence layer and repositories does support (or better: eat) this configuration and I can't estimate in which kind of problems you're gonna run. But I guess it's a try worth.
Good luck!

TYPO3 FAL: enable Alt text and Link for custom domain field

I have a "Products" extension with a db table "tx_xxxproducts_domain_model_product" having a field "accessories":
'accessories' => array(
'exclude' => 0,
'label' => 'LLL:EXT:xxx_products/Resources/Private/Language/locallang_db.xlf:tx_xxxproducts_domain_model_product.accessories',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('accessories', array(
'appearance' => array(
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference',
'collapseAll' => TRUE,
),
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
),
This field should have references to images.
It works, but the file references only have the fields Title and Description.
How can I add Link and Alternative Text, as the default Images CType has?
Thank you.
I found the answer in tt_content's TCA:
'accessories' => array(
'exclude' => 0,
'label' => 'LLL:EXT:xxx_products/Resources/Private/Language/locallang_db.xlf:tx_xxxproducts_domain_model_product.accessories',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('accessories', array(
'appearance' => array(
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference',
'collapseAll' => TRUE,
),
'foreign_types' => array(
'0' => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
)
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
),
Check the 'foreign_types' key.
TYPO3 v8 Change => https://docs.typo3.org/typo3cms/TCAReference/ColumnsConfig/Type/Inline.html#file-abstraction-layer
'overrideChildTca' => [
'types' => [
Instead of
'foreign_types' => [
add this in your array element 'config', after 'appearance' for example:
'foreign_types' => array(
'0' => array(
'showitem' => '--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => array(
'showitem' => '--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => array(
'showitem' => '--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => array(
'showitem' => '--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => array(
'showitem' => '--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => array(
'showitem' => '--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette'
),
),

cakephp 2.4 upload an image

i'm trying to upload an image and make a thumbnail of this image by using this Behavior (github) tutorial
I'm using the blog tutorial on cakephp website.
I'm getting this following errors each time I want to upload the images. I'm dowloading an .jpeg file
Invalid file type. Only .jpg, .jpeg, .png, .gif allowed.
My Model/Post.php
<?php
class Post extends AppModel {
public $validate = array(
'title' => array(
'rule' => 'notEmpty'
),
'body' => array(
'rule' => 'notEmpty'
)
);
public $actsAs = array('ImageUpload' => array(
'image' => array(
'required' => false,
'directory' => 'img/uploads/',
'allowed_mime' => array('image/jpeg', 'image/pjpeg', 'image/gif', 'image/png'),
'allowed_extension' => array('.jpg', '.jpeg', '.png', '.gif'),
'allowed_size' => 2097152,
'random_filename' => true,
'resize' => array(
'thumb' => array(
'directory' => 'img/uploads/thumbs/',
'phpThumb' => array(
'far' => 1,
'bg' => 'FFFFFF',
'zc' => 0
),
'width' => 230,
'height' => 150
),
'max' => array(
'directory' => 'img/uploads/thumbs/',
'phpThumb' => array(
//'far' => 1,
//'bg' => 'FFFFFF',
'zc' => 0
),
'width' => 400,
'height' => 300
)
)
)
)
);
}

how to enable cakephp media plugin to upload pdf files and docs

I apply the media plugin in my project but this is only for jpeg and png..
you can see in the demo...
demo
There is a validation that allow pdf files but doesnt work.
in attachment.php
var $validate = array(
'file' => array(
'resource' => array('rule' => 'checkResource'),
'access' => array('rule' => 'checkAccess'),
'location' => array('rule' => array('checkLocation', array(
MEDIA_TRANSFER, '/tmp/'
))),
'permission' => array('rule' => array('checkPermission', '*')),
'size' => array('rule' => array('checkSize', '5M')),
'pixels' => array('rule' => array('checkPixels', '1600x1600')),
'extension' => array('rule' => array('checkExtension', false,
array(
'jpg', 'jpeg', 'png', 'tif', 'tiff', 'gif', 'pdf', 'tmp'
))),
'mimeType' => array('rule' => array('checkMimeType', false, array(
'image/jpeg', 'image/png', 'image/tiff', 'image/gif',
'application/pdf'
)))),
'alternative' => array(
'rule' => 'checkRepresent',
'on' => 'create',
'required' => false,
'allowEmpty' => true,
));
this is the default configuration but doesnt work for pdf files only for images.
If you are using CakePHP 2.x, I would recommend the AjaxMultiUpload plugin which should take care of this for you:
http://bakery.cakephp.org/articles/srs2012/2012/03/12/ajaxmultiupload_plugin_for_cake_2_0_x_and_2_1

Meio upload behavior - zoom crop not working

I'm using this MeioUpload Behavior. And i installed both phpThumb component and phpThumb vendor.
Thumbnail generation is working fine but zoom-cropping is not.
Here is my code. You can see i've tried every possible variables. I also set every default zc or zoom_crop variables I found in component and vendor to 1. 1 is the same as C anyway.
var $actsAs = array('MeioUpload' => array( 'filename' => array(
'dir' => "uploads/images",
'create_directory' => true,
'allowed_mime' => array('image/jpeg', 'image/pjpeg', 'image/gif', 'image/png'),
'allowed_ext' => array('.jpg', '.jpeg', '.png', '.gif'),
'thumbsizes' => array(
'small' => array('width'=>65, 'height'=>60,'zc'=>"C", 'zoomCrop' => "C", 'zoom_crop'=>"C"),
'medium' => array('width'=>159, 'height'=>130, 'zc'=>"C", 'zoomCrop' => "C", 'zoom_crop'=>"C"),
'large' => array('width'=>480, 'height'=>320,'zc'=>"C", 'zoomCrop' => "C", 'zoom_crop'=>"C")
)
)
)
);
Any idea?
in latest version is necessary to define thumbnail precisely. I'm not sure if this solve your problem with script in older version.
var $actsAs = array(
'MeioUpload' => array(
'img_file' => array(
'create_directory' => true,
'allowed_mime' => array('image/jpeg', 'image/pjpeg', 'image/png'),
'allowed_ext' => array('.jpg', '.jpeg', '.png'),
'zoomCrop' => true,
'thumbsizes' => array(
'normal' => array('width' => 400, 'height' => 300),
'small' => array('width' => 80, 'height' => 80,'maxDimension' => '', 'thumbnailQuality' => 100, 'zoomCrop' => true),
),
'default' => 'default.jpg'
)
));
Ok, I gave up the use of MeioUpload to generate-and-save thumbnails.
Instead, I generate thumbnails on-the-fly, directly using phpThumb.
Like this
<img src="<?=$this->webroot?>phpThumb/phpThumb.php?src=../uploads/images/<?=$event['Image'][0]['filename']?>&w=159&h=130&zc=1" alt="Event Picture">
It's a little sacrifice for performance but every easy and flexible.

Resources