I am currently using the MeioUpload Plugin located here:
MeioUpload
The file uploading is all working like a charm, but the thumbnails are not being generated.
Has anyone else had this issue? I am using cakePHP 2.1.
I have followed the readme file strictly.
I was able to get this working by adding this code into the model:
class Image extends AppModel {
var $actsAs = array(
'MeioUpload.MeioUpload' => array(
'filename' => array(
'thumbsizes' => array(
'320x90' => array(
'width' => 320,
'height' => 90
)
)
)
)
);
}
You can vary the size of the thumbnail with the given parameters above.
Related
I'm trying to create a XML import module that will convert given file to CSV format and then use that CSV to import categories and products.
I have a working configuration page made with getContent() it basically calls a method that generates this form via $helper->generateForm(). $helper is a HelperForm() object.
protected function getConfigForm()
{
return array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'type' => 'file',
'label' => $this->l('XML file'),
'name' => 'XMLIMPORT_XML_FILE',
'desc' => $this->l('Select file you wish to import.'),
'required' => true
),
array(
'col' => 3,
'type' => 'text',
'prefix' => '<i class="icon icon-envelope"></i>',
'desc' => $this->l('Enter a valid email address'),
'name' => 'XMLIMPORT_LINES',
'label' => $this->l('Records per file'),
),
),
'submit' => array(
'title' => $this->l('Save'),
),
),
);
}
I need to get this data to my XML converter. How do I upload a file (around 10-20MB) to Prestashop to be then able to do other stuff with it? How to save it permanently on the server?
I tried doing this:
return array(
'XMLIMPORT_XML_FILE' => Configuration::get('XMLIMPORT_XML_FILE', null),
'XMLIMPORT_LINES' => Configuration::get('XMLIMPORT_LINES', 1000)
);
And after that this:
$form_values = $this->getConfigFormValues(); // returned array from above
foreach (array_keys($form_values) as $key)
Configuration::updateValue($key, Tools::getValue($key));
And later using my own class for XML conversion like this, hoping that it will give me file handle.
$xml_converter = new XMLToCSVConverter(Configuration::get('XMLIMPORT_XML_FILE'), 'output', 'example_products.php');
Apparently it didn't as nothing happens. The class itself is working fine outside of Prestashop module. The constructor is __construct($xml_file, $csv_filename, $template_file).
I need to pass the file I upload to that constructor. I've been struggling for days now.
#edit: I can see the contents of the file inside the HTTP call when submit is clicked. But how do I pass that file to my class?
As far as I remember 'type' => 'file', doesn't actually save any values in the database. This type is only meant to output a file field in your form.
After submitting, you should then do you custom processing with $_FILES['XMLIMPORT_XML_FILE'] : move to upload/ or whereever you want.
'XMLIMPORT_XML_FILE' => Configuration::get('XMLIMPORT_XML_FILE', null), won't return you anything. After uploading you my wish to save the uploaded file path here, but it won't show up next time in the form unless you build the output yourself.
Module configratuon is meant to save text config values. Handling files is trickier and you have to do them yourself each time.
EDIT:
To intercept the saving process, look up the submit button name and make an if statement:
public function getContent() {
if(Tools::isSubmit('submitButtonName')) {
error_log(print_r($_FILES, 1));
}
}
There's probably a function postProcess which does the same (it looks like you copied the methods from a default module).
prestashop handles the image upload with ImageManager class, this class contains more methods which are useful for handling image upload, resize etc.. so its better refer the default homeslider module for the image upload using a module. This module is handling the image upload process in postProcess method with the help of ImageManager class, this class methods will do the all the processes related to upload.
I'm using cakephp-upload plugin of jose gonzalez to upload images to our app. By default, they're being saved in a directory like this: webroot/files/user/photo/{user_id} which is fine, except for when we want to display such images using $this->Html->image() which searches for images in the webroot/img directory.
I have already tried to display the images with
echo $this->Html->image('../files/user/photo/' .
$user['User']['photo_dir'] . '/' .
$user['User']['photo']);
which works but I was wondering if there's some way to tell this plugin to save into the img directory? The documentation doesn't mention any of that.
And also, is there any way to tell the $this->Form->input('User.photo', array('type' => 'file')); to accept only image files?
as you can see in this file, path is set like:
public $defaults = array(
'rootDir' => null,
'pathMethod' => 'primaryKey',
'path' => '{ROOT}webroot{DS}files{DS}{model}{DS}{field}{DS}',
...
you could change it to make:
'path' => '{ROOT}webroot{DS}img{DS}'
and for your second question, you could use accept attribute, like:
$this->Form->input('User.photo',
array(
'type' => 'file',
'options' => array('accept' => 'image/*')
)
);
I'am trying to generate thumbnails with uploaded images in CakePHP.
I have worked with Rails and I used paperclip for that purpose, is there any way to do the same with CakePHP?
to be clear, I want to shrink the images keeping the ratio and then crop them in order to get them in the size I want.
If you have PHP available, you can try phpThumb, which does all that for you and much more. It can crop, zoom-crop, transform, blur, contrast...etc etc, and it auto-creates the thumbnails and keeps them in cache so it doesn't have to re-crop...etc each time the image is loaded.
It's also VERY simple to install and use, which is a big plus.
For CakePHP, you can just put the phpthumb folder in your webroot/ directory and use it just like normal.
Sounds like you might be looking for something like my Polyclip plugin. It's not feature-complete so I haven't documented it very well yet (I'll work on that as soon as I can), but it is in production and the core functionality that's in place seems to do what I need. Here's how I have it deployed with an Attraction model.
public $actsAs = array(
'Polyclip.attachable' => array(
'Image' => array(
'Thumbnails' => array(
'medium' => array( 'width' => 250, 'height' => 250, 'method' => 'resize_to_fit' ),
'square' => array( 'width' => 100, 'height' => 100, 'method' => 'resize_to_fill' ),
'sidebar' => array( 'width' => 290, 'height' => 100, 'method' => 'resize_to_fill' )
)
)
)
);
This attaches an image to the attraction with 3 thumbnails created automatically. As I said, it's not documented, but it's out there to fill the need you're looking to fill.
I'm using the Magento Soap Api to upload pictures of products. I can't seem to specify the name I wish Magento so save the file as on the server even though I specify the "name" as per the Magento documentation.
I'm using Magento 1.2.1.2 and can't upgrade as the site uses modules that break in newer version.
Any thoughts on how I can specify the file name that Magento saves the image as?
The code I'm using:
$client->call(
$session_id,
'catalog_product_attribute_media.create',
array(
$sku,
array(
'file' => array(
'content' => base64_encode(file_get_contents($filename)),
'mime' => $imageinfo['mime'],
'name' => $filename
),
'label' => $description,
'types' => array(
'image',
'small_image',
'thumbnail'
),
'exclude' => FALSE
)
)
);
You can't specify the filename. The only solution would be for you change the Magento files to allow a filename as suggested in this thread. For your convenience I've included the solution below (and adapted it based on the fact that you're sending the filename as name above):
Modify ./app/code/core/Mage/Catalog/Model/Product/Attribute/Media/Api.php:
You'll want to replace $fileName = 'image.' . $this->_mimeTypes[$data['file']['mime']]; with:
if ( ! empty($data['file']['name']) )
$fileName = $data['file']['name'];
else
$fileName = 'image.' . $this->_mimeTypes[$data['file']['mime']];
If you feel a little more adventurous, you could extend the class instead of changing it and override the create function with your own functionality.
I'm using Meioupload on a website built with CakePHP, and it is working fine for having multiple upload fields. The problem I have now is that if person A uploads a picture called 'me.jpg' and then person B uploads a picture called 'me.jpg', person B's will overwrite the first upload.
Is there a way in Meioupload to change the filename as the picture is uploaded? E.g. add the person's username to the start so it would look like 'persona_me.jpg' and 'personb_me.jpg'?
This is the code I currently have:
var $actsAs = array('MeioUpload' => array(
'picture' => array(
'dir' => 'files/device_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'=>100, 'height'=>100),
'medium' => array('width'=>240, 'height'=>180),
'large' => array('width'=>640, 'height'=>480)
)));
Thanks for any help
Add this in your Meio Upload declaration: 'uploadName' => 'url_slug', where url_slug is field you are submitting with the form (actually, it might be a field in the schema, it's both on my app).
from what I can remember when i was using meio upload, images were placed in a directory with the name of the pk, something like /images//filename.ext
for the most part you want to keep the file name, as it can be used for SEO.