Yii Framework Forum: Techniques for secure file upload / download - Yii Framework Forum

Jump to content

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

Techniques for secure file upload / download Rate Topic: -----

#1 User is offline   JamesBarnsley 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 359
  • Joined: 18-November 10
  • Location:UK

Posted 08 May 2012 - 10:43 AM

Hi,

I have a directory with files in it, the files are named based on an ID in a database table which the directory is synchronized with using PHP.

The trouble with this method is anyone can simply type ...

1.zip
24.zip

They can download any file they want, does anyone have any techniques for making a secure file download system?
0

#2 User is offline   Haensel 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 441
  • Joined: 14-January 11
  • Location:Vienna (Austria)

Posted 08 May 2012 - 11:06 AM

Just a quick thought but you know who is logged in via Yii::app()->user->id. So you could add a method to your CWebUser class like

public function isOwnerOfFile($filename)
{
    return $this->id==(int)$filename;
}


and in your controller

public function actionDownload($filename)
{
    if(!$this->isOwnerOfFile($filename))
        throw new CHttpException(403,'Not allowed');
}

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