]> jfr.im git - uguu.git/blobdiff - static/php/upload.php
Update README.md
[uguu.git] / static / php / upload.php
index 877e5ef1f64b9feb5faa72268b2759ae159728c4..d1a4d4c1c31604f13a8cbd05972d2f1a6384fc92 100644 (file)
@@ -17,8 +17,8 @@ function generateName($file)
     global $doubledots;
 
     // We start at N retries, and --N until we give up
-    $tries = POMF_FILES_RETRIES;
-    $length = POMF_FILES_LENGTH;
+    $tries = UGUU_FILES_RETRIES;
+    $length = UGUU_FILES_LENGTH;
     //Get EXT
     $ext = pathinfo($file->name, PATHINFO_EXTENSION);
     //Get mime
@@ -56,13 +56,15 @@ function generateName($file)
 
         //Check if mime is blacklisted
         if (in_array($type_mime, unserialize(CONFIG_BLOCKED_MIME))) {
-            throw new Exception('Extension type not allowed.');
+            http_response_code(415);
+            throw new Exception('Filetype not allowed!');
             exit(0);
         }
 
         //Check if EXT is blacklisted
         if (in_array($ext, unserialize(CONFIG_BLOCKED_EXTENSIONS))) {
-            throw new Exception('Extension type not allowed.');
+            http_response_code(415);
+            throw new Exception('Filetype not allowed!');
             exit(0);
         }
 
@@ -99,10 +101,11 @@ function uploadFile($file)
     $newname = generateName($file);
 
     // Store the file's full file path in memory
-    $uploadFile = POMF_FILES_ROOT.$newname;
+    $uploadFile = UGUU_FILES_ROOT.$newname;
 
     // Attempt to move it to the static directory
     if (!move_uploaded_file($file->tempfile, $uploadFile)) {
+        http_response_code(500);
         throw new Exception(
             'Failed to move file to destination',
             500
@@ -111,6 +114,7 @@ function uploadFile($file)
 
     // Need to change permissions for the new file to make it world readable
     if (!chmod($uploadFile, 0644)) {
+        http_response_code(500);
         throw new Exception(
             'Failed to change file permissions',
             500
@@ -131,7 +135,7 @@ function uploadFile($file)
     return [
         'hash' => $file->getSha1(),
         'name' => $file->name,
-        'url' => POMF_URL.rawurlencode($newname),
+        'url' => UGUU_URL.rawurlencode($newname),
         'size' => $file->size,
     ];
 }