Cloudinary, jQuery limit to single image upload - php

I'm using Cloudinary, JQuery with PHP but can't find any option on how to limit upload to just one file.
In my cl_image_upload_tag I tried setting "html" => array("multiple" => false))); but this has no effect.
I read the Cloudinary documentation but couldn't see any option for it, any ideas thanks

I found that changing the line from;
echo cl_image_upload_tag('xx', array("tags" => "xxxx", "callback" => $cors_location, "html" => array("multiple" => true)));
To this;
echo cl_image_upload_tag('xx', array("tags" => "xxxx", "callback" => $cors_location ));
ie. removing the multiple did the trick, setting it to false didnt work, nor did changing limitMultiFileUploads in the js file.

Related

Set cookies in configuration using PHP

I'd like to print a document with PDFreactor using PHP.
Unfortunately, the document generation fails when specifying cookies in the configuration. Leaving out the cookies line prints our login page - with is correct as the page displays a login screen if no session cookie could be identified.
$config = array(
"document"=> "http://localhost",
"logLevel"=> LogLevel::DEBUG,
"javaScriptMode" => JavaScriptMode::ENABLED_TIME_LAPSE,
"enableDebugMode" => true,
"cookies" => array("sid" => "abcdefghijklmno")//<-- problematic line
);
Could anybody verify that cookie passing fails with PHP or give advice about the correct syntax?
The issue is caused by a mistake in the syntax of your cookie configuration. The correct syntax would be:
$config = array(
"document"=> "http://localhost",
"logLevel"=> LogLevel::DEBUG,
"javaScriptMode" => JavaScriptMode::ENABLED_TIME_LAPSE,
"enableDebugMode" => true,
"cookies" => array(
array("key" => "sid", "value" => "abcdefghijklmno") // <-- corrected
)
);
For multiple cookies:
"cookies" => array(
array("key" => "cookiename1", "value" => "cookievalue1"),
array("key" => "cookiename2", "value" => "cookievalue2")
)

CSRFProtector PHP library won't submit any form data

I am using the CSRFProtector library for PHP (https://github.com/mebjas/CSRF-Protector-PHP) and as soon as I turn it on all forms stop submitting and I get an error:
403 Access Forbidden by CSRFProtector!
My config file contains:
return array(
"CSRFP_TOKEN" => "ctkn",
"logDirectory" => "log",
"failedAuthAction" => array(
"GET" => 0,
"POST" => 0),
"errorRedirectionPage" => "",
"customErrorMessage" => "",
"jsPath" => "js/csrfprotector.js",
"jsUrl" => "ABS PATH TO js/csrfprotector.js",
"tokenLength" => 10,
"disabledJavascriptMessage" => "",
"verifyGetFor" => array()
);
and the log file for CSRF shows:
{"timestamp":1433842328,"HOST":"MYDOMAIN.COM","REQUEST_URI":"\/add","requestType":"POST",
"query":{"title":"234","date":"08\/06\/2015","submit":""},
"cookie":{"ctkn":"3c8c7dfebc","__insp_uid":"1173752613",
"PHPSESSID":"SESSION_ID","_ok":"3274-991-10-2674","__utma":"98457856.2008088440.1420840286.1431630284.1432025914.10",
"__utmc":"98457856","__utmz":"98457856.1429793890.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)","__insp_wid":"801086210",
"__insp_nv":"false","__insp_ref":"aHR0cHM6Ly93d3cubmF0dXJhbGhyLm5ldC9sb2dpbg==",
"__insp_identity":"33101","__insp_norec_sess":"true","__insp_slim":"1433237660812",
"mp_3a3715a3d0ca553aea5e93832d489346_mixpanel":"{\"distinct_id\": \"14adaecc111146-0576c4449-63161675-232800-14adaecc1122e6\",
\"$initial_referrer\": \"$direct\",\"$initial_referring_domain\": \"$direct\"}",
"_okbk":"cd5=available,cd4=true,vi5=0,vi4=1433789710017,vi3=active,vi2=false,vi1=false,
cd8=chat,cd6=0,cd3=false,cd2=0,cd1=0,","_gat":"1","_ga":"GA1.2.2008088440.1420840286",
"_oklv":"1433842325615,1q2TBnOvCYwsP8Vp452Bb0OMFOHE0QN6","olfsk":"olfsk31493824627250433",
"_okac":"96642aff6954f6ce73ba12dfbb632117","_okla":"1","wcsid":"1q2TBnOvCYwsP8Vp452Bb0OMFOHE0QN6",
"hblid":"BpAXj2n915tZ7ULn452Bb0OMFPI1k134"}}
Can anyone tell me why this is failing? What do I need to do to allow this genuine request but still stop any illicit ones?
For me, the problem was that I'm using a bootstrap confirmation modal to confirm before submitting the forum. When I checked the $_POST object, I found that it doesn't include the csrf_token.
You might have the same problem.
you have changes CSRFP_TOKEN in config file, so you need to change in js file too..
i.e.
CSRFP_TOKEN: 'ctkn'

cakephp upload plugin - define what directory to save files in

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/*')
)
);

Mandrill email attachments file path

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

Cake PHP redirect with parameters in url

I have a page that I want to redirect to that requires parameters in the URL:
http://www.example.com/myController/myAction/param1:val1/param2:val2
I know that there is a CakePHP redirect function for redirecting that works as follows:
$this->redirect(array("controller" => "myController",
"action" => "myAction",
$data_can_be_passed_here),
$status, $exit);
How do I add the parameters that I want as part of the url using the above function?
I would think that there might be another element that I could add to array so that I can pass along param1:val1 and param2:val2.
Any help would be greatly appreciated!
I do not know why I was not able to find this in the CakePHP documentation, but I did finally figure out the solution. I am posting it here in case anyone else has the same problem. (If someone knows where this is in the documentation please post it as well, thanks!)
To redirect to the URL:
http://www.example.com/myController/myAction/param1:val1/param2:val2
You can use:
$this->redirect(array("controller" => "myController",
"action" => "myAction",
"param1" => "val1",
"param2" => "val2",
$data_can_be_passed_here),
$status,
$exit);
Hope it helps!
If you need to redirect with exactly get parameters, then pass '?' index to $url array argument:
$this->redirect(
array(
"controller" => "myController",
"action" => "myAction",
"?" => array(
"param1" => "val1",
"param2" => "val2"
),
$data_can_be_passed_here
),
$status,
$exit
);
It redirects to /myController/muAction/...?param1=val1&param2=val2
This is true at least in CakePHP 1.3
Instead, you can use this format also
<?php
$this->redirect('/controller/action/par1:par1/par2:par2/');
?>
<?php
$this->redirect('/controller/action/id/10/name/hello/');
?>
I usually do something like this:$this->redirect(['action' => 'view', $id, 'admins' => true]);
Hope it will help you.
In CakePHP 4.2 it seems that "param" => "val1" doesnt work anymore.
This is the way you go:
return $this->redirect(['controller'=>'mycontroller','action' => 'myview', 'myparameter']);

Categories