Yii Framework Forum: Force a 'file/save as' - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Force a 'file/save as' Rate Topic: -----

#1 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,035
  • Joined: 30-October 09
  • Location:UK

Posted 10 February 2010 - 12:33 PM

Does Yii have any built-in functionality to force a "file/save as" dialog when clicking on a file URL?
0

#2 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,035
  • Joined: 30-October 09
  • Location:UK

Posted 11 February 2010 - 05:00 AM

Anyone able to advise?
0

#3 User is offline   dimis283 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 277
  • Joined: 24-January 09

Posted 11 February 2010 - 06:20 AM

The simplest is to create a action to download this file.
I thing there are 'download files' classes at http://www.phpclasses.org/
Posted Image
0

#4 User is offline   Volli 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 29-May 09

Posted 11 February 2010 - 11:06 AM

http://www.yiiframew...sendFile-detail in combination with a controller action
0

#5 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,035
  • Joined: 30-October 09
  • Location:UK

Posted 11 February 2010 - 12:45 PM

Can you give me exaple please, I have no idea how to do this.
0

#6 User is offline   dimis283 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 277
  • Joined: 24-January 09

Posted 11 February 2010 - 05:58 PM

The first class that I have in mind is this and codeigniter simiral class.
I thing you can get the code of this class and use it as extension.
Posted Image
0

#7 User is offline   Volli 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 29-May 09

Posted 12 February 2010 - 10:52 AM

Here is an example. Call it with yourdomain.tld/index.php?r=test/download
The file lies in the folder "download" under your document root.

Controller Test:

/**
 * Download of the file
 */
public function actionDownload()
{
	$file = '/download/document.pdf';
	return Yii::app()->getRequest()->sendFile(basename($file), @file_get_contents(Yii::app()->getBasePath().'/..'.$file));
}

0

#8 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,035
  • Joined: 30-October 09
  • Location:UK

Posted 12 February 2010 - 12:50 PM

No actually I want to create a link to the file itself, e.g. document.docx

In IE by default it opens up the document within the browser window. But I have seem some sites whereby you are always given the option to save the file even if it is a direct link to the file.
0

#9 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,035
  • Joined: 30-October 09
  • Location:UK

Posted 16 February 2010 - 09:31 AM

I don't suppose I could add .htaccess rules to do this? The only file types I am dealing with are .pdf and .doc
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users