Skip to content

Instantly share code, notes, and snippets.

@jangedoo
Last active August 5, 2016 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jangedoo/1f09d282bf8c42bbc5db612bc8df57a2 to your computer and use it in GitHub Desktop.
Save jangedoo/1f09d282bf8c42bbc5db612bc8df57a2 to your computer and use it in GitHub Desktop.
CakePHP file upload
//in upload.ctp,
<?php echo $this->Form->input('proxyfile',array('type' => 'file', 'class' => 'btn btn-default btn-file')) ?>
//in controller
public function upload(){
$filename = WWW_ROOT . "/files/".$this->data['Proxy']['proxyfile']['name'];
/* copy uploaded file */
if (move_uploaded_file($this->data['Proxy']['proxyfile']['tmp_name'],$filename)) {
/* save message to session */
$this->Session->setFlash('File uploaded successfuly. You can view it <a href="/app/webroot/files/'.$this->data['Proxy']['proxyfile']['name'].'">here</a>.');
/* redirect */
$this->redirect(array('action' => 'index'));
} else {
/* save message to session */
$this->Session->setFlash('There was a problem uploading file. Please try again.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment