summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorJuuso Lapinlampi <wub@partyvan.eu>2016-05-23 03:06:34 +0200
committerJuuso Lapinlampi <wub@partyvan.eu>2016-05-23 03:15:38 +0200
commit3e7be281df3f22eebc0bdffa9878f0361a417885 (patch)
tree8c46f32bcfdadd5d904656531b2b2c0704b269bb /static
parent1dccd0719729b66cb6aa5a7963a9c22d79c1ddb6 (diff)
upload.php: Apply DRY to POMF_FILES_ROOT.$newname
Don't repeat yourself with multiple POMF_FILES_ROOT.$newname for full file path. Use a variable pointer $uploadFile. Improves code readability and robustness.
Diffstat (limited to 'static')
-rw-r--r--static/upload.php8
1 files changed, 6 insertions, 2 deletions
diff --git a/static/upload.php b/static/upload.php
index a218c71..eef714e 100644
--- a/static/upload.php
+++ b/static/upload.php
@@ -128,13 +128,17 @@ function upload_file($file)
// Generate a name for the file
$newname = generate_name($file);
+ // Store the file's full file path in memory
+ $uploadDir = POMF_FILES_ROOT;
+ $uploadFile = $uploadDir . $newname;
+
// Attempt to move it to the static directory
- if (!move_uploaded_file($file->tempfile, POMF_FILES_ROOT.$newname)) {
+ if (!move_uploaded_file($file->tempfile, $uploadFile)) {
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)) {
+ if (!chmod($uploadFile, 0644)) {
throw new Exception('Failed to change file permissions', 500);
}