Skip to content

Instantly share code, notes, and snippets.

@CeoFred
Created June 4, 2019 02:31
Show Gist options
  • Save CeoFred/c5d5bdd464551a0a3d24ef002201edce to your computer and use it in GitHub Desktop.
Save CeoFred/c5d5bdd464551a0a3d24ef002201edce to your computer and use it in GitHub Desktop.
uploadfiles with size and type check in php
$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