summaryrefslogtreecommitdiff
path: root/static/upload.php
diff options
context:
space:
mode:
authorJuuso Lapinlampi <wub@partyvan.eu>2016-05-23 02:37:33 +0200
committerJuuso Lapinlampi <wub@partyvan.eu>2016-05-23 02:59:15 +0200
commit1dccd0719729b66cb6aa5a7963a9c22d79c1ddb6 (patch)
tree5ef54e7b1ee47eed3792b117cb72c54481746c84 /static/upload.php
parent57b8f96ae7d86a7d86c03416df37d4f79889f2fb (diff)
upload.php: Unnest upload_file() if-else expressions
As phpmd (PHP Mess Detector) linter says: "An if expression with an else branch is never necessary." Well, at least almost never necessary. Improves readability and resolves phpmd cleancode lint errors.
Diffstat (limited to 'static/upload.php')
-rw-r--r--static/upload.php60
1 files changed, 30 insertions, 30 deletions
diff --git a/static/upload.php b/static/upload.php
index c7d5ea7..a218c71 100644
--- a/static/upload.php
+++ b/static/upload.php
@@ -129,38 +129,38 @@ function upload_file($file)
$newname = generate_name($file);
// Attempt to move it to the static directory
- if (move_uploaded_file($file->tempfile, POMF_FILES_ROOT.$newname)) {
- // Need to change permissions for the new file to make it world readable
- if (chmod(POMF_FILES_ROOT.$newname, 0644)) {
- // Add it to the database
- // 'expire' support is deprecated since version 2.1.0. It may be
- // removed in a future release.
- $q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, '.
- 'expire, delid) VALUES (:hash, :orig, :name, :size, :date, '.
- ':exp, :del)');
-
- // Common parameters binding
- $q->bindValue(':hash', $file->get_sha1(), PDO::PARAM_STR);
- $q->bindValue(':orig', strip_tags($file->name), PDO::PARAM_STR);
- $q->bindValue(':name', $newname, PDO::PARAM_STR);
- $q->bindValue(':size', $file->size, PDO::PARAM_INT);
- $q->bindValue(':date', date('Y-m-d'), PDO::PARAM_STR);
- $q->bindValue(':exp', null, PDO::PARAM_STR); // Deprecated since version 2.1.0
- $q->bindValue(':del', sha1($file->tempfile), PDO::PARAM_STR);
- $q->execute();
-
- return array(
- 'hash' => $file->get_sha1(),
- 'name' => $file->name,
- 'url' => POMF_URL.$newname,
- 'size' => $file->size,
- );
- } else {
- throw new Exception('Failed to change file permissions', 500);
- }
- } else {
+ if (!move_uploaded_file($file->tempfile, POMF_FILES_ROOT.$newname)) {
throw new Exception('Failed to move file to destination', 500);
}
+
+ // Need to change permissions for the new file to make it world readable
+ if (!chmod(POMF_FILES_ROOT.$newname, 0644)) {
+ throw new Exception('Failed to change file permissions', 500);
+ }
+
+ // Add it to the database
+ // 'expire' support is deprecated since version 2.1.0. It may be
+ // removed in a future release.
+ $q = $db->prepare('INSERT INTO files (hash, originalname, filename, size, date, '.
+ 'expire, delid) VALUES (:hash, :orig, :name, :size, :date, '.
+ ':exp, :del)');
+
+ // Common parameters binding
+ $q->bindValue(':hash', $file->get_sha1(), PDO::PARAM_STR);
+ $q->bindValue(':orig', strip_tags($file->name), PDO::PARAM_STR);
+ $q->bindValue(':name', $newname, PDO::PARAM_STR);
+ $q->bindValue(':size', $file->size, PDO::PARAM_INT);
+ $q->bindValue(':date', date('Y-m-d'), PDO::PARAM_STR);
+ $q->bindValue(':exp', null, PDO::PARAM_STR); // Deprecated since version 2.1.0
+ $q->bindValue(':del', sha1($file->tempfile), PDO::PARAM_STR);
+ $q->execute();
+
+ return array(
+ 'hash' => $file->get_sha1(),
+ 'name' => $file->name,
+ 'url' => POMF_URL.$newname,
+ 'size' => $file->size,
+ );
}
/**