function processHeaders($headers, $fileName, $mime_dl, &$type, &$isDown, &$isHTML, &$isImage){ array_shift($headers); $type = getContentType($headers); $isDown = (isset($mime_dl[$type]) ? $mime_dl[$type] : true); if(eregi("image",$type)) $isImage = true; elseif(eregi("text/html",$type)) $isHTML = true; if($isDown) $headers[] = "Content-Disposition: attachment;" . " filename=$fileName"; return $headers; }
function getData() { $tmpName = $_FILES['file']['tmp_name']; assertNotEmpty($tmpName, "missing file"); $imageWidth = getParameter("imageWidth"); $imageHeight = getParameter("imageHeight"); $contentType = getContentType(); debug($contentType); if (($contentType == "image/jpeg" || $contentType == "image/x-png" || $contentType == "image/png" || $contentType == "image/gif") && !empty($imageWidth) && !empty($imageHeight)) { resizeImage($tmpName, $imageWidth, $imageHeight); } $fp = fopen($tmpName, 'r'); $length = filesize($tmpName); debug("File size: {$length}"); $content = fread($fp, $length); fclose($fp); return $content; }
function net2ftp_module_sendHttpHeaders() { // -------------- // This function sends HTTP headers // -------------- global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result; if ($net2ftp_globals["state2"] != "") { // Get file $text = ftp_readfile("", $net2ftp_globals["directory"], $net2ftp_globals["entry"]); if ($net2ftp_result["success"] == false) { return false; } // Send headers header("Content-Type: " . getContentType($net2ftp_globals["entry"])); header("Content-Disposition: inline; filename=\"" . $net2ftp_globals["entry"] . "\""); // Send file echo $text; flush(); // Close the connection header("Connection: close"); } }
function sendDownloadHeaders($filename, $filesize) { // -------------- // This function sends download headers to the browser // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_globals; // ------------------------------------------------------------------------- // Clean the input, and encode the filename with htmlentities // ------------------------------------------------------------------------- $filename = trim($filename); $filename_html = htmlEncode3($filename); // ------------------------------------------------------------------------- // Check which is the content type and disposition // ------------------------------------------------------------------------- $content_type = getContentType($filename); $content_disposition = "attachment"; if (strpos($filename, ".zip")) { $content_disposition = "inline"; } // ------------------------------------------------------------------------- // Send the headers - Internet Explorer // From PhpMyAdmin 3.5.2.0 file core.lib.php // ------------------------------------------------------------------------- header('Expires: ' . date(DATE_RFC1123)); // rfc2616 - Section 14.21 header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 if ($net2ftp_globals["browser_agent"] == "IE") { header('Pragma: public'); } else { header('Pragma: no-cache'); // HTTP/1.0 header('Last-Modified: ' . date(DATE_RFC1123)); } header('Content-Description: File Transfer'); header('Content-Disposition: attachment; filename="' . $filename_html . '"'); header('Content-Type: ' . $content_type); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . $filesize); }
function sendDownloadHeaders($filename, $filesize) { // -------------- // This function sends download headers to the browser // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_globals; // ------------------------------------------------------------------------- // Clean the input, and encode the filename with htmlentities // ------------------------------------------------------------------------- $filename = trim($filename); $filename_html = htmlEncode3($filename); // ------------------------------------------------------------------------- // Check which is the content type and disposition // ------------------------------------------------------------------------- $content_type = getContentType($filename); $content_disposition = "attachment"; if (strpos($filename, ".zip") !== false) { $content_disposition = "inline"; } // ------------------------------------------------------------------------- // Send the headers - Internet Explorer // From PhpMyAdmin 2.8.0.2 file export.php // ------------------------------------------------------------------------- header("Content-Type: " . $content_type); header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT"); if ($net2ftp_globals["browser_agent"] == "IE") { header("Content-Disposition: {$content_disposition}; filename=\"" . $filename_html . "\""); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: public"); } else { // Firefox needs an asterisk to enable filenames with special characters header("Content-Disposition: {$content_disposition}; filename*=\"" . $filename_html . "\""); header("Pragma: no-cache"); } header("Content-Description: {$filename_html}"); header("Content-Length: {$filesize}"); header("Connection: close"); }
case 'text/plain': $format = FORMAT_NTRIPLES; break; case 'text/turtle': $format = FORMAT_TURTLE; break; default: $format = FORMAT_RDF_JSON; } $graph = $tripod->describeResource(base64_decode($encodedFqUri)); } while (++$i < READ_REPEAT_NUM); if ($graph->is_empty()) { $app->response()->setStatus(404); } else { $output = getFormattedGraph($graph, $format); $app->response()->headers()->set('Content-type', getContentType($format)); echo $output; } }); $app->delete('/:encodedFqUri', function ($storeName, $podName, $encodedFqUri) use($app, $tripodOptions) { $tripodOptions['statsConfig'] = getStat($app, $tripodOptions); $tripod = new \Tripod\Mongo\Driver($podName, $storeName, $tripodOptions); $oldGraph = $tripod->describeResource(base64_decode($encodedFqUri)); $tripod->saveChanges($oldGraph, new \Tripod\ExtendedGraph()); }); $app->post('/', function ($storeName, $podName) use($app, $tripodOptions) { $tripodOptions['statsConfig'] = getStat($app, $tripodOptions); $tripod = new \Tripod\Mongo\Driver($podName, $storeName, $tripodOptions); $rawGraphData = $app->request()->getBody(); $graph = new \Tripod\Mongo\MongoGraph(); $graph->add_rdf($rawGraphData);
function main() { if (isset($_FILES['picturefile']['name'])) { $referersplit = preg_split("/[?]/", $_SERVER['HTTP_REFERER']); $referer = $referersplit[0]; try { if ($_FILES["picturefile"]["size"] > 5 * 1024 * 1024 || $_FILES['picturefile']['tmp_name'] == null) { throw new Exception('File too large!'); } else { if (getContentType($_FILES['picturefile']['name']) == null) { throw new Exception('File type not supported!'); } else { $filename = generateUniqueId() . "-" . $_FILES['picturefile']['name']; $tmpName = $_FILES['picturefile']['tmp_name']; $image = new SimpleImage(); $image->load($tmpName); $imageWasResized = false; if ($image->getHeight() > 1024) { $image->resizeToHeight(1024); } if ($image->getWidth() > 1024) { $image->resizeToWidth(1024); } $image->save($tmpName); // Saving even if not resized, to reduce compression level of file $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); fclose($fp); updateOrInsertImage($filename, $content); } } header('Location: ' . $referer . "?uploadresult=true&filelocation=php/io.php?file=" . $filename); return true; } catch (Exception $e) { header('Location: ' . $referer . "?uploadresult=false&errormsg=" . $e->getMessage()); return true; } } if (isset($_GET['id'])) { $slideshowId = $_GET['id']; $slideshowSrc = getSlideshow($slideshowId); $slideshow = array('id' => $slideshowId, 'src' => $slideshowSrc); sendJSONResponse(json_encode($slideshow)); return true; } if (isset($_POST['id'], $_POST['key'], $_POST['src'])) { $slideshowId = $_POST['id']; $slideshowKey = $_POST['key']; $slideshowToSave = $_POST['src']; if (isCorrectKey($slideshowId, $slideshowKey)) { updateSlideshow($slideshowId, $slideshowToSave); } else { throw new Exception("ERROR key is wrong"); } $result = array('id' => $slideshowId); sendJSONResponse(json_encode($result)); return true; } if (isset($_POST['create'])) { $id = generateUniqueId(); $key = generateRandomLegibleString(); createEmptySlideshow($id, $key); $idAndKey = array('id' => $id, 'key' => $key); sendJSONResponse(json_encode($idAndKey)); return true; } if (isset($_GET['file'])) { $imageId = $_GET['file']; $image = getImage($imageId); header("Content-type: " . getContentType($imageId)); print $image; return true; } return false; }
/** * @todo vérification du ratio du propriétaire (suffisant ou non pour autoriser le téléchargement) * @todo support de lourds fichiers * @author Alban Truc * @param $token * @param int $downloadSpeed par défaut 100 KB/s * @since 15/06/2014 * @return array */ function anonymousDownload($token, $downloadSpeed = 102400) { if ($token == '') { return array('error' => 'Invalid link.'); } $elementPdoManager = new ElementPdoManager(); $elementCriteria = array('state' => (int) 1, 'downloadLink' => $token); $element = $elementPdoManager->findOne($elementCriteria); if (!$element instanceof Element) { return $element; } //récupère le code et l'extension de notre élément $refElementPdoManager = new RefElementPdoManager(); $fieldsToReturn = array('code' => TRUE, 'extension' => TRUE); $refElement = $refElementPdoManager->findById($element->getRefElement(), $fieldsToReturn); if (!array_key_exists('error', $refElement)) { if (preg_match('/^4/', $refElement['code']) || preg_match('/^9/', $refElement['code'])) { // dossier ou non reconnu, pas d'extension à rajouter return array('error' => 'Donwload not available on folder or unrecognized element'); } } else { return $refElement; } $filePath = PATH . $element->getOwner() . $element->getServerPath(); $fileName = $element->getName() . $refElement['extension']; $fullFilePath = $filePath . $fileName; $fileSize = round($element->getSize() * 1024); set_time_limit(0); if ($fd = fopen($fullFilePath, 'r')) { header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=\"{$fileName}\""); header("Content-Transfer-Encoding: binary"); header("Content-length: {$fileSize}"); $fileExtension = pathinfo($fullFilePath, PATHINFO_EXTENSION); //déterminer le Content-Type $ctype = getContentType($fileExtension); header("Content-Type: {$ctype}"); $file = @fopen($fullFilePath, 'rb'); if ($file) { while (!feof($file)) { print fread($file, 1024 * $downloadSpeed); flush(); usleep(500); if (connection_status() != 0) { @fclose($file); die; } } @fclose($file); } } }
// delete file unlink($content_dir . $uuid . "/" . $filename); } } } //end ignore dots } // end while dirscan } // end unzip add_DBJob($mysqli, DB, $uuid, "IngestContent"); echo '{"success":"success"}'; exit; } // end if zip rename($upload_dir . $org_filename, $content_dir . $uuid . "/" . $uuid . "." . $extension); if ($extension == "blend") { # add blend-file to Database add_DBContent($mysqli, $org_filename, $uuid, "blender", $extension); } else { # add uploaded File to Database $content_type = getContentType($extension); add_DBContent($mysqli, $org_filename, $uuid, $content_type, $extension); } add_DBJob($mysqli, DB, $uuid, "IngestContent"); echo '{"success":"success"}'; exit; } } echo '{"error":"upload failed"}'; exit;
function add_channel($url, $folderid = 0, $title_ = null, $descr_ = null, $tags = null) { if (!$url || strlen($url) <= 7) { return array(-2, "Invalid URL {$url}"); } if (!is_numeric($folderid)) { return array(-2, "Invalid folderid {$folderid}"); } $url = sanitize(str_replace('&', '&', $url), RSS_SANITIZER_URL); $urlDB = rss_real_escape_string($url); //htmlentities($url); $res = rss_query("select count(*) as channel_exists from " . getTable("channels") . " where url='{$urlDB}'"); list($channel_exists) = rss_fetch_row($res); if ($channel_exists > 0) { // fatal return array(-2, "Looks like you are already subscribed to this channel"); } $res = rss_query("select 1+max(position) as np from " . getTable("channels")); list($np) = rss_fetch_row($res); if (!$np) { $np = "0"; } // Here we go! //error_reporting(E_ALL); $old_level = error_reporting(E_ERROR); $rss = fetch_rss($url); error_reporting($old_level); if ($rss) { if ($title_) { $title = rss_real_escape_string($title_); } elseif (is_object($rss) && array_key_exists('title#', $rss->channel)) { if (array_key_exists('title', $rss->channel)) { $title = rss_real_escape_string($rss->channel['title']); } else { $title = " "; } } else { $title = ""; } if (is_object($rss) && array_key_exists('link', $rss->channel)) { $siteurl = rss_real_escape_string(htmlentities($rss->channel['link'])); } else { $siteurl = ""; } $refreshinterval = 0; if (is_object($rss) && array_key_exists('syn', $rss->channel)) { $syn = $rss->channel['syn']; if (array_key_exists('updateperiod', $syn)) { if ("hourly" == $syn['updateperiod']) { if (array_key_exists('updatefrequency', $syn)) { $refreshinterval = 60 * $syn['updatefrequency']; } } } } if ($descr_) { $descr = rss_real_escape_string($descr_); } elseif (is_object($rss) && array_key_exists('description', $rss->channel)) { $descr = rss_real_escape_string($rss->channel['description']); } else { $descr = ""; } //lets see if this server has a favicon $icon = ""; if (getConfig('rss.output.showfavicons')) { // if we got nothing so far, lets try to fall back to // favicons if ($icon == "" && $siteurl != "") { $match = get_host($siteurl, $host); $uri = "http://" . $host . "favicon.ico"; if ($match && getContentType($uri, $contentType)) { if (preg_match("/image\\/x-icon/", $contentType)) { $icon = $uri; } } } } $private = preg_match('|(https?://)([^:]+:[^@]+@)(.+)$|', $url); if ($title != "") { $title = strip_tags($title); $descr = strip_tags($descr); // add channel to root folder by default if (!$folderid) { $folderid = getRootFolder(); } list($title, $urlDB, $siteurl, $folderid, $descr, $icon) = rss_plugin_hook('rss.plugins.feed.new', array($title, $urlDB, $siteurl, $folderid, $descr, $icon)); $mode = RSS_MODE_UNREAD_STATE; if ($private) { $mode |= RSS_MODE_PRIVATE_STATE; } $sql = "insert into " . getTable("channels") . " (title, url, siteurl, parent, descr, dateadded, icon, position, mode, daterefreshed)" . " values ('{$title}', '{$urlDB}', '{$siteurl}', {$folderid}, '{$descr}', now(), '{$icon}', {$np}, {$mode}, '0000-00-00 00:00:00')"; rss_query($sql); $newid = rss_insert_id(); if ($icon && cacheFavicon($icon)) { rss_query("update " . getTable("channels") . " set icon='blob:" . $icon . "'" . " where id={$newid}"); } if ($tags != "") { __exp__submitTag($newid, $tags, "'channel'"); } if (false == empty($refreshinterval)) { setProperty($newid, 'rss.config.refreshinterval', $refreshinterval); } return array($newid, ""); } else { // non-fatal, will look further return array(-1, "I'm sorry, I couldn't extract a valid RSS feed from <a href=\"{$url}\">{$url}</a>."); } } else { global $MAGPIE_ERROR; $retError = "I'm sorry, I couldn't retrieve <a href=\"{$url}\">{$url}</a>."; if ($MAGPIE_ERROR) { $retError .= "\n<br />{$MAGPIE_ERROR}\n"; } // non-fatal, will look further return array(-1, $retError); } }
* http://code.google.com/p/minify/ * */ $expires = 60 * 60 * 24 * 365 * 10; // length of expires headers - 10 yrs $cachedir = dirname(__FILE__) . '/cache'; $validFiles = array(); // put params in order, maybe not necessary but just in case ksort($_GET, SORT_STRING); // determine valid file requests foreach ($_GET as $requestedFile) { if (inWhiteList($requestedFile)) { $validFiles[] = $requestedFile; } } $contentType = getContentType($validFiles); $encoding = getEncoding(); // create unique filename based on valid file requests // we use this for caching to disk $cachefile = md5(implode($validFiles) . $encoding); $cachefullpath = $cachedir . '/' . $cachefile; // check if this file has already been created/cached if (file_exists($cachefullpath)) { if ($fp = fopen($cachefullpath, 'rb')) { setHeaders($encoding, $contentType, filesize($cachefullpath), $expires); fpassthru($fp); fclose($fp); exit; } } // request not yet cached