웹 서버에 저장된 파일을 다운로드하는 방법을 찾고있었습니다. 그러나, 내가 찾고있는 것을 찾을 수 없었습니다.CakePHP 2.0 파일 다운로드
내 파일을 웹 서버에 업로드했습니다 (현재 작동 중입니다). 대상 경로는 데이터베이스에 저장됩니다.
다운로드 링크로 파일 이름과 함께 다운로드 할 수있는 파일 목록을 만들 수 있기를 원합니다.
public function upload() {
$this->layout = 'staff';
$this->set('upload', $this->StaffUpload->find('all'));
if($this->request->is('post')){
$file = $this->request->data['Upload']['browsefile'];
$id = $this->Auth->User('usersId');
$staff = $this->Staff->find('first', array('conditions' => array('usersId' => $id)));
$dest_file = ROOT . DS . 'app' .DS. 'staff_uploads' . DS . $file['name'];
if(!is_dir(ROOT . DS . 'app' .DS. 'staff_uploads')) {
mkdir(ROOT . DS . 'app' .DS. 'staff_uploads');
}
if(move_uploaded_file($file['tmp_name'], $dest_file)) {
$this->StaffUpload->create();
$data = array(
'title' => $this->request->data['Upload']['filetitle'],
'dest' => $dest_file,
'description' => $this->request->data['Upload']['filedescription'],
'type' => $this->request->data['Upload']['uploadtype'],
'title' => $this->request->data['Upload']['filetitle'],
'staffId' => $staff['Staff']['id'],
'date_uploaded' => date('Y-m-d H:i:s')
);
if($this->StaffUpload->save($data)) {
$this->Session->setFlash('The file has been successfully uploaded!', 'alert_box', array('class' => 'alert-success'), 'uploads');
$this->redirect(array('action' => 'upload'));
}
}
}
}
것은 위의 코드는 잘 작동 :
여기 직원 컨트롤러 아래에있는 업로드 방법에 대한 코드입니다. 이제는 다운로드 링크로 제목을 다운로드 할 수 있기를 바랍니다.
내가 다운로드 링크이보기에 표시 할, resources.ctp :
<h1>Resources</h1> <hr/> </div><!-- end well --> </div><!-- end col-12 --> </div><!-- end bigCallout -->
과 웹 사이트 컨트롤러에서이 기능 :
public function resources() {
$this->layout = 'website';
}
그 기능을 무엇에 넣어야할지 모르겠습니다. 그리고 또 다른 기능을 만들어야한다는 것도 압니다. 나는 CakePHP에 익숙하지 않다. Media View가 더 이상 사용되지 않아서 사용하지 않았습니다.
감사합니다.
당신은 미디어 파일을 다운로드하기 위해 아래와 같은 기능을 사용할 수 있습니다