mirror of
https://github.com/danpros/htmly.git
synced 2026-04-17 11:16:00 +05:30
Refactor "if" condition for "$_FILES" array
remove unnecessary nested if condition to one liner using AND Boolean operator.
This commit is contained in:
parent
ee3e479ebd
commit
faa522d827
1 changed files with 18 additions and 20 deletions
38
upload.php
38
upload.php
|
|
@ -26,27 +26,25 @@ if (login()) {
|
|||
mkdir($dir, 0755, true);
|
||||
}
|
||||
|
||||
if (isset($_FILES)) {
|
||||
if (isset($_FILES['file'])) {
|
||||
$tmp_name = $_FILES['file']['tmp_name'];
|
||||
$name = basename($_FILES['file']['name']);
|
||||
$error = $_FILES['file']['error'];
|
||||
$path = $dir . $timestamp . '-' . $name;
|
||||
|
||||
$check = getimagesize($tmp_name);
|
||||
|
||||
if($check !== false) {
|
||||
if ($error === UPLOAD_ERR_OK) {
|
||||
$extension = pathinfo($name, PATHINFO_EXTENSION);
|
||||
if (!in_array(strtolower($extension), $whitelist)) {
|
||||
$error = 'Invalid file type uploaded.';
|
||||
} else {
|
||||
move_uploaded_file($tmp_name, $dir . $timestamp . '-' . $name);
|
||||
}
|
||||
if (isset($_FILES) && isset($_FILES['file'])) {
|
||||
$tmp_name = $_FILES['file']['tmp_name'];
|
||||
$name = basename($_FILES['file']['name']);
|
||||
$error = $_FILES['file']['error'];
|
||||
$path = $dir . $timestamp . '-' . $name;
|
||||
|
||||
$check = getimagesize($tmp_name);
|
||||
|
||||
if($check !== false) {
|
||||
if ($error === UPLOAD_ERR_OK) {
|
||||
$extension = pathinfo($name, PATHINFO_EXTENSION);
|
||||
if (!in_array(strtolower($extension), $whitelist)) {
|
||||
$error = 'Invalid file type uploaded.';
|
||||
} else {
|
||||
move_uploaded_file($tmp_name, $dir . $timestamp . '-' . $name);
|
||||
}
|
||||
} else {
|
||||
$error = "File is not an image.";
|
||||
}
|
||||
} else {
|
||||
$error = "File is not an image.";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -61,4 +59,4 @@ if (login()) {
|
|||
} else {
|
||||
$login = site_url() . 'login';
|
||||
header("location: $login");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue