2020-06-12 21:31:10 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves a file to the corresponding podcast folder in `public/media`
|
|
|
|
*
|
2020-07-10 14:20:25 +02:00
|
|
|
* @param \CodeIgniter\HTTP\Files\UploadedFile $file
|
2020-06-12 21:31:10 +02:00
|
|
|
* @param string $podcast_name
|
|
|
|
* @param string $file_name
|
|
|
|
*
|
2020-06-26 16:34:52 +02:00
|
|
|
* @return string The episode's file path in media root
|
2020-06-12 21:31:10 +02:00
|
|
|
*/
|
|
|
|
function save_podcast_media($file, $podcast_name, $media_name)
|
|
|
|
{
|
|
|
|
$file_name = $media_name . '.' . $file->guessExtension();
|
|
|
|
|
|
|
|
// move to media folder and overwrite file if already existing
|
|
|
|
$file->move(
|
|
|
|
config('App')->mediaRoot . '/' . $podcast_name . '/',
|
|
|
|
$file_name,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
return $podcast_name . '/' . $file_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prefixes the root media path to a given uri
|
|
|
|
*
|
|
|
|
* @param mixed $uri URI string or array of URI segments
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function media_path($uri = ''): string
|
|
|
|
{
|
|
|
|
// convert segment array to string
|
|
|
|
if (is_array($uri)) {
|
|
|
|
$uri = implode('/', $uri);
|
|
|
|
}
|
|
|
|
$uri = trim($uri, '/');
|
|
|
|
|
|
|
|
return config('App')->mediaRoot . '/' . $uri;
|
|
|
|
}
|