Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ vendor
node_modules
.php-cs-fixer.cache
bundles
media_data/
.DS_Store
6 changes: 3 additions & 3 deletions core/models/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.'];
}

Expand Down Expand Up @@ -2803,7 +2803,7 @@ public function rand_file_location($args = [])

foreach ($requiredDirs as $checkDir) {
if (!file_exists($checkDir)) {
mkdir($checkDir);
mkdir($checkDir, 0755, true);
}
}

Expand Down
14 changes: 8 additions & 6 deletions public/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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)
Expand All @@ -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;
}

Expand All @@ -75,23 +77,23 @@ 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;
}

$result['file_id'] = $id;
$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 {
$result['info'] = [];
}

// 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']]);

Expand Down
Loading