Created
June 4, 2019 02:31
-
-
Save CeoFred/c5d5bdd464551a0a3d24ef002201edce to your computer and use it in GitHub Desktop.
uploadfiles with size and type check in php
This file contains hidden or 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
$logo = isset($_FILES['logo']) ? $_FILES['logo'] : null; | |
if ($logo['size'] > 300000) { | |
echo 'File size too large'; | |
return; | |
} | |
$type = explode('/', $logo['type']); | |
if ($type[0] != 'image') { | |
http_response_code(403); | |
echo 'Only pdf file type is allowed'; | |
return; | |
} | |
if ($logo['error']) { | |
http_response_code(409); | |
echo 'File could not be uploaded'; | |
return; | |
} | |
$filename = time() . uniqid() . '.' . $type[1]; | |
$uploaded = move_uploaded_file($logo['tmp_name'], '/uploads/company_logo/' . $filename); | |
if (!$uploaded || ($logo['error'])) { | |
http_response_code(409); | |
echo 'Company Logo could not uploaded'; | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment