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, 


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


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


SOLVED aws s3 pdf
1 Answers

Version: 2.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">


Created: 3 Oct '16

Last Reply: 3 Oct '16

Replies: 1

Views: 5903

Votes: 0

Welcome to Aero Coding!

Aero Coding is a CakePHP-focused Q&A community for professional and enthusiast cake bakers. It's built and run by you as part of the community.

Join Now Tour

Download Cakephp

Start baking your own CakePHP application!

Cakephp All Versions