Last active
August 5, 2016 15:18
-
-
Save jangedoo/1f09d282bf8c42bbc5db612bc8df57a2 to your computer and use it in GitHub Desktop.
CakePHP file upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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