note 20474 added to function.fpassthru

From: Date: Thu, 04 Apr 2002 17:25:13 +0000
Subject: note 20474 added to function.fpassthru
Groups: php.notes 
Request: Send a blank email to php-notes+get-28615@lists.php.net to get a copy of this message
Here is a final working copy that won't freak out Microsoft Explorer if you are using sessions. Thanks to everyone else who came before. This is not as simple as I thought it would be. the user would pass a call to the page: http://mysite/getfile.php?file=products.pdf include 'base.inc'; // inlcude base code, start session and manage users // This loads the file global from the post/get variables // For security reasons register globals is disabled LoadPostGet('file'); $filename = '/data/files/' . $file; if(file_exists($filename)){ $FILECMD = '/usr/bin/file'; $contentType = ''; $fp=popen("$FILECMD -bin $filename", 'r'); if (!$fp) $contentType='application/octet-stream'; else { while($string=fgets($fp, 1024)) $contentType .= $string; pclose($fp); } if(strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'MSIE')){ // IE cannot download from sessions without a cache header('Cache-Control: public'); } header("Content-type: $contentType"); header("Content-Disposition:inline; filename=\"".$file."\""); header("Content-length:".(string)(filesize($filename))); $fd=fopen($filename,'rb'); while(!feof($fd)) { print fread($fd, 4096); } fclose($fd); }else{ print "File Not Found"; } -- http://www.php.net/manual/en/function.fpassthru.php http://master.php.net/manage/user-notes.php?action=edit+20474 http://master.php.net/manage/user-notes.php?action=delete+20474 http://master.php.net/manage/user-notes.php?action=reject+20474

« previous php.notes (#28615) next »