Category: Views

Q: CakePHP 2 download link from view using alternative file name

Hi Aero Coding:

I have a project written in CakePHP 2 that provides pdf storage and sharing service to end users. The pdf name of download links are same as is the hash name in s3, and pdf file name was generated form objectId-like unique ID, for example, 

files/ca8W7mc0ZUx43bxTuSGN.pdf

Recently the client wants to use "readable" file names like

Evans_Ebook.pdf

instead of non-readable objectIds. The original file name was saved in DB that can be retrieved by objectId.

* download.ctp:

 <?php echo $this->Html->link('Download PDF Now', $f['File']['url'], array(
    'class' => 'btn btn-primary btn-xs',
    'rel'   => 'nofollow'
  )); ?>

* data

$f['File']['url']; // s3 URL
$f['File']['name']; // original file name
$f['File']['owner']; // owner ID..etc

Thanks

SOLVED aws s3 pdf
1 Answers

Version: 2.2

user
Betts

2

Accepted by Betts

Add download attribute to <a> tag should work in your case : )

 <?php echo $this->Html->link('Download PDF Now', $f['File']['url'], array(
    'class' => 'btn btn-primary btn-xs',
    'rel'   => 'nofollow',
    'download' => $f['File']['name']
  )); ?>

HTML 4.01 & HTML 5 HTML <a> download Attribute

<a download="filename">
Kristi
Kristi

137