Returns the headers for a browser download.
public downloadHeaders ( string $filename = 'unknown', string $cType = null, boolean $inline = false, string $cLength = null ) | ||
$filename | string | The filename of the download. |
$cType | string | The content-type description of the file. |
$inline | boolean | True if inline, false if attachment. |
$cLength | string | The content-length of this file. |
$defaultimg .= "blankmovie.png"; break; default: $mime = 'image/png'; $defaultimg .= "blankalbum.png"; break; } $image = file_get_contents($defaultimg); } else { if ($_GET['thumb']) { $thumb_data = $art->get_thumb($size); $etag .= '-' . $_GET['thumb']; } $mime = isset($thumb_data['thumb_mime']) ? $thumb_data['thumb_mime'] : $art->raw_mime; $image = isset($thumb_data['thumb']) ? $thumb_data['thumb'] : $art->raw; } } if (!empty($image)) { $extension = Art::extension($mime); $filename = scrub_out($filename . '.' . $extension); // Send the headers and output the image $browser = new Horde_Browser(); if (!empty($etag)) { header('ETag: ' . $etag); header('Cache-Control: private'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time())); } header("Access-Control-Allow-Origin: *"); $browser->downloadHeaders($filename, $mime, true); echo $image; }
if (!Access::check('interface', 100) or AmpConfig::get('demo_mode')) { UI::access_denied(); exit; } UI::show_header(); /* Switch on action boys */ switch ($_REQUEST['action']) { /* This re-generates the config file comparing * /config/ampache.cfg to .cfg.dist */ case 'generate_config': ob_end_clean(); $current = parse_ini_file(AmpConfig::get('prefix') . '/config/ampache.cfg.php'); $final = generate_config($current); $browser = new Horde_Browser(); $browser->downloadHeaders('ampache.cfg.php', 'text/plain', false, filesize(AmpConfig::get('prefix') . '/config/ampache.cfg.php.dist')); echo $final; exit; case 'reset_db_charset': Dba::reset_db_charset(); show_confirmation(T_('Database Charset Updated'), T_('Your Database and associated tables have been updated to match your currently configured charset'), AmpConfig::get('web_path') . '/admin/system.php?action=show_debug'); break; case 'show_debug': $configuration = AmpConfig::get_all(); if ($_REQUEST['autoupdate'] == 'force') { $version = AutoUpdate::get_latest_version(true); } require_once AmpConfig::get('prefix') . '/templates/show_debug.inc.php'; break; default: // Rien a faire
/** * install_create_config * * Attempts to write out the config file or offer it as a download. */ function install_create_config($download = false) { $config_file = AmpConfig::get('prefix') . '/config/ampache.cfg.php'; /* Attempt to make DB connection */ Dba::dbh(); $params = AmpConfig::get_all(); if (empty($params['database_username']) || empty($params['database_password']) && strpos($params['database_hostname'], '/') !== 0) { Error::add('general', T_("Invalid configuration settings")); return false; } // Connect to the DB if (!Dba::check_database()) { Error::add('general', T_("Database Connection Failed Check Hostname, Username and Password")); return false; } $final = generate_config($params); // Make sure the directory is writable OR the empty config file is if (!$download) { if (!check_config_writable()) { Error::add('general', T_('Config file is not writable')); return false; } else { // Given that $final is > 0, we can ignore lazy comparison problems if (!file_put_contents($config_file, $final)) { Error::add('general', T_('Error writing config file')); return false; } } } else { $browser = new Horde_Browser(); $browser->downloadHeaders('ampache.cfg.php', 'text/plain', false, strlen($final)); echo $final; exit; } return true; }
} // don't abort the script if user skips this media because we need to update now_playing ignore_user_abort(true); // Format the media name $media_name = $media->get_stream_name() . "." . $media->type; header('Access-Control-Allow-Origin: *'); // Generate browser class for sending headers $browser = new Horde_Browser(); /* If they are just trying to download make sure they have rights * and then present them with the download file */ if ($_GET['action'] == 'download' and AmpConfig::get('download')) { debug_event('play', 'Downloading file...', 5); // STUPID IE $media_name = str_replace(array('?', '/', '\\'), "_", $media->f_file); $browser->downloadHeaders($media_name, $media->mime, false, $media->size); $fp = fopen(Core::conv_lc_file($media->file), 'rb'); $bytesStreamed = 0; if (!is_resource($fp)) { debug_event('Play', "Error: Unable to open {$media->file} for downloading", '2'); exit; } if (!$share_id) { if ($_SERVER['REQUEST_METHOD'] != 'HEAD') { debug_event('play', 'Registering download stats for {' . $media->get_stream_name() . '}...', '5'); $sessionkey = $sid ?: Stream::get_session(); $agent = Session::agent($sessionkey); $location = Session::get_geolocation($sessionkey); Stats::insert($type, $media->id, $uid, $agent, $location, 'download'); } }
public function prepare_media($media) { $client = $this->createClient(); if ($client != null) { set_time_limit(0); // Generate browser class for sending headers $browser = new Horde_Browser(); $media_name = $media->f_artist_full . " - " . $media->title . "." . $media->type; $browser->downloadHeaders($media_name, $media->mime, false, $media->size); $file = $this->get_rel_path($media->file); $output = fopen('php://output', 'w'); $metadata = $client->getFile($file, $output); if ($metadata == null) { debug_event('play', 'File not found on Dropbox: ' . $file, 5); } fclose($output); } return null; }