コード例 #1
0
ファイル: lib_ezmam.php プロジェクト: jingyexu/ezcast
/**
 * Deletes the media from the asset
 * @param type $album
 * @param type $asset
 * @param type $media
 * @return type 
 */
function ezmam_media_delete($album_name, $asset_name, $media_name)
{
    $repository_path = ezmam_repository_path();
    if ($repository_path === false) {
        return false;
    }
    if (!ezmam_album_exists($album_name)) {
        ezmam_last_error("Trying to delete {$album_name} which doesn't exist!");
        return false;
    }
    if (!ezmam_asset_exists($album_name, $asset_name)) {
        ezmam_last_error("Trying to delete {$asset_name} which doesn't exist!");
        return false;
    }
    if (!ezmam_media_exists($album_name, $asset_name, $media_name)) {
        ezmam_last_error("Trying to delete {$media_name} which doesn't exist!");
        return false;
    }
    $path = ezmam_repository_path() . '/' . ezmam_media_getpath($album_name, $asset_name, $media_name);
    if (is_file($path)) {
        $path = dirname($path);
    }
    // First we empty the directory
    $dir = opendir($path);
    if ($dir === false) {
        ezmam_last_error("Unable to open folder {$path}");
        return false;
    }
    while (($file = readdir($dir)) !== false) {
        if ($file != "." && $file != "..") {
            if (is_dir($path . '/' . $file)) {
                exec('rm -rf ' . $path . '/' . $file);
            } else {
                unlink($path . '/' . $file);
            }
            //single file media
        }
    }
    // Then we delete it
    $res = rmdir($path);
    if (!$res) {
        ezmam_last_error("Unable to delete folder {$path}");
        return false;
    }
    return true;
}
コード例 #2
0
ファイル: web_distribute.php プロジェクト: jingyexu/ezcast
function view_media()
{
    global $accepted_media_qualities;
    global $accepted_media_types;
    global $input;
    // 0) Sanity checks
    if (!ezmam_album_exists($input['album'])) {
        error_print_http(404);
        log_append('warning', 'view_media: tried to access non-existant album ' . $input['album']);
        die;
    }
    if (!ezmam_asset_exists($input['album'], $input['asset'])) {
        error_print_http(404);
        log_append('warning', 'view_media: tried to access non-existant asset ' . $input['asset'] . ' from album ' . $input['album']);
        die;
    }
    if (!ezmam_album_token_check($input['album'], $input['token']) && !ezmam_asset_token_check($input['album'], $input['asset'], $input['token'])) {
        error_print_http(404);
        log_append('warning', 'view_media: tried to access asset ' . $input['asset'] . ' from album ' . $input['album'] . ' with invalid token ' . $input['token']);
        die;
    }
    if (!isset($input['quality'])) {
        $input['quality'] = 'high';
    }
    if (!accepted_quality($input['quality'])) {
        error_print_http(403);
        log_append('warning', 'view_media: tried to access forbidden quality "' . $input['quality'] . '"');
        die;
    }
    if (!accepted_type($input['type'])) {
        error_print_http(403);
        log_append('warning', 'view_media: tried to access forbidden media type "' . $input['type'] . '"');
        die;
    }
    // 1) First we retrieve the media path
    $quality = strtolower($input['quality']);
    $type = strtolower($input['type']);
    $media_name = $quality . '_' . $type;
    $media_handle = ezmam_media_getpath($input['album'], $input['asset'], $media_name, false);
    // If we couldn't find our file, we check whether it exists in another quality
    if (!$media_handle) {
        if ($quality == 'low') {
            $quality = 'high';
        } else {
            if ($quality == 'high') {
                $quality = 'low';
            }
        }
        $media_name = $quality . '_' . $type;
        $media_handle = ezmam_media_getpath($input['album'], $input['asset'], $media_name, false);
        // If we still can't find a file, we just tell the users so
        if (!$media_handle) {
            error_print_http(404);
            log_append('view_media: couldn\'t find the media file for asset ' . $input['asset'] . ' of album ' . $input['album']);
            die;
        }
    }
    // 2) Then we save some statistics on it
    ezmam_media_viewcount_increment($input['album'], $input['asset'], $media_name, $input['origin']);
    // 3) And finally, we deliver it!
    $filename = suffix_remove($input['album']);
    $filename .= '_-_';
    $filename .= get_user_friendly_date($input['asset'], '_', true, 'fr-ASCII');
    //add a quality part in filename
    if ($quality == 'low') {
        $quality_fn_part = 'SQ';
    } else {
        $quality_fn_part = 'HQ';
    }
    $filename .= '_' . $quality_fn_part;
    //add a type video/slide part in filename
    if ($type == 'cam') {
        $type_fn_part = 'video';
    } else {
        $type_fn_part = 'slide';
    }
    $filename .= '_' . $type_fn_part;
    //  header('Content-Type: video/x-m4v');
    header('Content-Type: video/mp4');
    if (isset($_SERVER['HTTP_RANGE'])) {
        rangeDownload($media_handle);
    } else {
        header('Content-Disposition: attachment; filename=' . $filename . '.m4v');
        //header('Content-Transfer-Encoding: binary');
        //header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Content-Length: ' . filesize($media_handle));
        header('Accept-Ranges: bytes');
        //readfile($media_handle);
        //fpassthru($fh);
        passthru('/bin/cat ' . escapeshellarg($media_handle));
        fclose($fh);
    }
}
コード例 #3
0
/**
 * returns an assoc array of original medias relative path
 * @global string $repository_path
 * @param string $album
 * @param string $asset
 */
function submit_itm_get_medias($album, $asset)
{
    global $repository_path;
    $medias = array();
    //scan all of asset's media for originals
    $media_meta_list = ezmam_media_list_metadata_assoc($album, $asset);
    foreach ($media_meta_list as $media => $media_meta) {
        if (substr($media, 0, 9) == "original_" && $media_meta['disposition'] == "file") {
            //its an original and its a movie
            $media_type = substr($media, 9);
            //cam or slide
            //add an assoc element: media=>relativepath_to_media
            $medias[$media] = ezmam_media_getpath($album, $asset, $media, true);
            if (!(file_exists($repository_path . "/" . $medias[$media]) && !is_dir($repository_path . "/" . $medias[$media]))) {
                myerror("{$repository_path}/{$media_file_path} is not a file");
            }
        }
        //endif original
    }
    //end foreach media
    return $medias;
}