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,
Related
In my web application I need to upload images from my system and use it in Yiistrap carausel. I copied the image into my images directory and gave the address .But its not recognizing , its not showing the image although I gave the correct adress of my image
My code for using the image in Yiistrap widgets.
<?php echo TbHtml::carousel(array(
array('image' => '/var/www/store3/images/download.jpg/830x477', 'label' => 'First Thumbnail label', 'caption' => 'image1'),
array('image' => '/var/www/store3/images/download1.jpg/830x477', 'label' => 'Second Thumbnail label', 'caption' => 'image2'),
)); ?>
I also tried all combinations by removing the full path naming ,adding the relative path , but nothing seems to work .
The error I am getting is..
Failed to load resource: the server responded with a status of 404 (Not Found)
Any body kindly help me with this .I am stuck up
Try this. It worked at my end. Using Yii's baseurl is the best way to reference directories.
<?php echo TbHtml::carousel(array(
array('image' => Yii::app()->request->baseUrl.'/images/download.jpg', 'label' => 'First Thumbnail label', 'caption' => 'image1'),
array('image' => Yii::app()->request->baseUrl.'/images/download1.jpg', 'label' => 'Second Thumbnail label', 'caption' => 'image2'),
)); ?>
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 add some attachments to an email that is being sent using the mandrill api via a php wrapper. I have tried a number of different things to try to successfully attach the file but to no avail.
I am using cakephp 2.x but I don't think that has any particular significance in this instance (maybe it does?!).
I am using the php wrapper maintained by mandrill at https://bitbucket.org/mailchimp/mandrill-api-php
Here is the code:
$mandrill = new Mandrill(Configure::read('Site.mandrill_key'));
$params = array(
'html' => '
<p>Hi '.$user['User']['name'].',</p>
<p>tIt is that time of the year again.<br />
Please login to the website members area and upload your renewal requirements.</p>
<p>Kind regards.</p>',
"text" => null,
"from_email" => Configure::read('Site.email'),
"from_name" => Configure::read('Site.title'),
"subject" => "Renewal Pending",
"to" => array(array('email' => $user['User']['email'])),
"track_opens" => true,
"track_clicks" => true,
"auto_text" => true,
"attachments" => array(
array(
'path' => WWW_ROOT.'files/downloads/renewals',
'type' => "application/pdf",
'name' => 'document.pdf',
)
)
);
$mandrill->messages->send($params, true);
}
This shows that an attachment has been added to the email and is a pdf but the actual pdf has not been attached.
I also tried by adding the path directly onto the file as in:
"attachments" => array(
array(
'type' => "application/pdf",
'name' => WWW_ROOT.'files/downloads/renewals/document.pdf',
)
I have googled and read every article I can find but cannot find any specific reference as to how I should specify the path for mandrill to correctly attach my attachment.
Any help will be greatly appreciated.
OK. So thanks to Kaitlin for her input.
The PHP way to deal with this is to get the file and then base64_encode it:
$attachment = file_get_contents(WWW_ROOT.'files/downloads/file.pdf');
$attachment_encoded = base64_encode($attachment);
and then in the attachments part of the mandrill array you pass the :
"attachments" => array(
array(
'content' => $attachment_encoded,
'type' => "application/pdf",
'name' => 'file.pdf',
)
So easy! Thanks again Kaitlin!
It looks like you're passing a parameter called path, but the Mandrill API doesn't take the path of a file for attachments. If you're using the send or send-template call, attachments should be an associative array (hash) with three keys: type, name, and content.
The content parameter should be the contents of the file as a Base64 encoded string, so instead of path, you'll want to get the file contents, Base64 encode them, and then pass them in a parameter called content instead of path.
You can see the full details of the parameters, including for attachments, in the Mandrill API docs here: https://mandrillapp.com/api/docs/messages.html#method=send
I am trying to upload multiple photos into a photoset post to Tumblr. I am using PHP to connect to Tumblr and authenticate. I can post individual photos and video but can't seem to figure out photosets. There are other posts on Stack that help other languages except for PHP.
I have a directory of photos. I get the contents of those file and put them into an array using scandir. But when I try to post that array to Tumblr, it doesn't work.
$scanned_directory = array_diff(scandir($directory), array('..', '.'));
$connection->post("blog/$hostname/post", array('type' => 'photo',
'state' => $dest, 'link' => $sourceurl, 'source' => $sourceurl,
'caption' => $caption, 'tags' => $tags , 'data' =>
$scanned_directory));
What am I doing wrong?
Thanks for the help!
I think you should iterate the $scanned_directory variable and make sure you don't submit the just the path and filename to the Tumblr API, but the actual contents of your image file with file_get_contents(), a working example would look probably something like this:
foreach($scanned_directory as $filename){
$data[] = file_get_contents($directory.'/'.$filename);
}
$connection->post("blog/$hostname/post", array('type' => 'photo', 'state' => $dest, 'link' => $sourceurl, 'source' => $sourceurl, 'caption' => $caption, 'tags' => $tags , 'data' => $data));
That should likely do the trick, just make sure the $directory variable is actually an absolute path to your image directory (e.g. '/var/www/myhost.tld/public/images/photoset')
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.