diff --git a/.gitignore b/.gitignore index cd4b2e60..e6186d3b 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ vendor node_modules .php-cs-fixer.cache bundles +media_data/ +.DS_Store diff --git a/core/models/Media.php b/core/models/Media.php index ee676046..c30e8704 100644 --- a/core/models/Media.php +++ b/core/models/Media.php @@ -1932,7 +1932,7 @@ public function save($args = []) } // move our file to its home - $file_src = OB_UPLOADS . '/' . $file_id; + $file_src = OB_MEDIA_UPLOADS . '/' . $file_id; if ($item['is_approved'] == 0) { $file_dest = OB_MEDIA_UNAPPROVED . $media_location . $filename; @@ -2175,7 +2175,7 @@ public function version_add($args = []) } // move file - if (!rename(OB_UPLOADS . '/' . $file_id, $dst_file)) { + if (!rename(OB_MEDIA_UPLOADS . '/' . $file_id, $dst_file)) { return [false, 'Error adding new version.']; } @@ -2803,7 +2803,7 @@ public function rand_file_location($args = []) foreach ($requiredDirs as $checkDir) { if (!file_exists($checkDir)) { - mkdir($checkDir); + mkdir($checkDir, 0755, true); } } diff --git a/public/upload.php b/public/upload.php index ee44b6a5..3335c652 100644 --- a/public/upload.php +++ b/public/upload.php @@ -5,6 +5,8 @@ require_once(__DIR__ . '/../core/init.php'); +use OpenBroadcaster\Base\Controller; + // COMPLETE AUTHENTICATION, usually handled by api.php $user = OBFUser::get_instance(); @@ -35,7 +37,7 @@ } // define our class, create instance, handle upload. -class Upload extends OBFController +class Upload extends Controller { // used by handle_upload() to get some important information about the uploaded media private function media_info($filename) @@ -57,14 +59,14 @@ public function handle_upload() $id = $this->db->insert('uploads', ['key' => $key, 'expiry' => strtotime('+24 hours')]); $input = fopen("php://input", "r"); - $target = fopen(OB_UPLOADS . '/' . $id, "w"); + $target = fopen(OB_MEDIA_UPLOADS . '/' . $id, "w"); $realSize = stream_copy_to_stream($input, $target); fclose($input); fclose($target); if ($realSize != (int) $_SERVER["CONTENT_LENGTH"]) { echo json_encode(['error' => 'File upload was not successful. Please try again.']); - unlink(OB_UPLOADS . '/' . $id); + unlink(OB_MEDIA_UPLOADS . '/' . $id); return; } @@ -75,7 +77,7 @@ public function handle_upload() } else { echo json_encode(['error' => 'File too large (max size ' . OB_MEDIA_FILESIZE_LIMIT . 'MB).']); } - unlink(OB_UPLOADS . '/' . $id); + unlink(OB_MEDIA_UPLOADS . '/' . $id); return; } @@ -83,7 +85,7 @@ public function handle_upload() $result['file_key'] = $key; // get ID3 data. - $id3_data = $models->media('getid3', ['filename' => OB_UPLOADS . '/' . $id]); + $id3_data = $models->media('getid3', ['filename' => OB_MEDIA_UPLOADS . '/' . $id]); if (count($id3_data) > 0) { $result['info'] = ['comments' => $id3_data]; } else { @@ -91,7 +93,7 @@ public function handle_upload() } // get some useful media information, insert it into the db with our file id/key. - $media_info = $this->media_info(OB_UPLOADS . '/' . $id); + $media_info = $this->media_info(OB_MEDIA_UPLOADS . '/' . $id); $this->db->where('id', $id); $this->db->update('uploads', ['format' => $media_info['format'], 'type' => $media_info['type'], 'duration' => $media_info['duration']]);