From 3e7be281df3f22eebc0bdffa9878f0361a417885 Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Mon, 23 May 2016 01:06:34 +0000 Subject: 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. --- static/upload.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'static') 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); } -- cgit v1.2.3