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.
Related
I created Cloudinary account and made a "posts" folder.
I want to store all images upload on posts folder but I don't know how to do that.
I'm using this package https://github.com/jrm2k6/cloudder
Here is a sample code:
\Cloudinary\Uploader::upload("myImage.jpg",
array("folder" => "my_folder/my_sub_folder/", "public_id" => "my_image", "overwrite" => TRUE,
"resource_type" => "image"))
So let's say the name of the folder is posts
$image_path = $request->file('image_name')->getRealPath();
Cloudder::upload($image_path, null, array("folder" => "posts", "overwrite" => TRUE, "resource_type" => "image"));
the null parameter allows cloudinary to generate a unique public id for the uploaded image.
public_id: "posts/unique_id.png",
Image file attachments in mandrill api working fine. But here,
'type' => 'image/jpeg',
'name' => "", // Here I didn't know what I am use
'content' => base64_encode(file_get_contents($img))
You can do something like
'name' => basename($img)
if you do not want to rename the image.
Hope this helps,
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 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.
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.