Skip to content

Instantly share code, notes, and snippets.

@anehkumar
Created September 29, 2020 08:16
Show Gist options
  • Save anehkumar/cbc08ac6c5f341610f6ea28e5c4ff0e3 to your computer and use it in GitHub Desktop.
Save anehkumar/cbc08ac6c5f341610f6ea28e5c4ff0e3 to your computer and use it in GitHub Desktop.
Sace Upload File cakephp 3
<?php
if($this->request->is('post')){
$user_id = $this->Auth->user('id');
$data = $this->request->getData();
$location = WWW_ROOT."prescription/";
$allowed_ext = ['png' ,'jpg', 'jpeg'];
$filename = $data['image_file']['name'];
$temp = $data['image_file']['tmp_name'];
$size = $data['file']['size'];
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
if(!in_array($ext, $allowed_ext) ) {
$msg = ["status" => 0, "msg" => "Select valid file to upload"];
}elseif($size > 5000000) {
$msg = ["status" => 0, "msg" => "File Size Exceeds 5MB limit"];
}else{
$newFileName = $user_id.date("dmyms")."-prec".$ext;
$uploadImage = move_uploaded_file($temp, $location.$newFileName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment