Created
September 29, 2020 08:16
-
-
Save anehkumar/cbc08ac6c5f341610f6ea28e5c4ff0e3 to your computer and use it in GitHub Desktop.
Sace Upload File cakephp 3
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
<?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