Upload A File
Auto adjust the table on mobile devices or when screen is thin to show in a nice format
Controller Action
public function uploadFile() {
if (!empty($this->request->getData())) {
$attachment = $this->request->getData('file');
$filename = $attachment->getClientFilename();
$typeOfUpload = $attachment->getClientMediaType();
$size = $attachment->getSize();
$uploadedFile = $attachment->getStream()->getMetadata('uri');
$error = $attachment->getError();
$csvFile = $uploadedFile;
$filename = APP.'Files'.DS.'uploadProducts_'.date('YmdHis').'.csv';
file_put_contents($filename,
file_get_contents($csvFile)
);
}
Template
<?= $this->Form->Create(null, array(
'novalidate' => true,
'type' => 'file'
)); ?>
<?= $this->Form->file('file', array('class' => 'btn btn-primary')); ?>
<br>
<?= $this->Form->button('Upload', array('class' => 'btn btn-primary')); ?>
<?= $this->Form->end(); ?>