note 51482 added to function.header

From: Date: Thu, 31 Mar 2005 21:56:04 +0000
Subject: note 51482 added to function.header
Groups: php.notes 
Request: Send a blank email to php-notes+get-87292@lists.php.net to get a copy of this message
Ok, maybe it can be usefull -- i was trying to save space on my disk and my transfer-rate, but i didn't want to sacrifice the quality of my pictures. So, it can be usefull for people like me. The file, when is sent to the server, is compressed in gzip: <?php $content = file_get_contents($_FILES['userfile']['tmp_name']); $content = gzencode($content,9); $id = fopen("/new/path/images/thename.png.gz","w+"); fwrite($id,$content); fclose($id); ?> So, it is saved in a new path, that cannot be accessed remotely, to avoid unwanted remote-users accessing it. But there's a script that offers it to the user: show_image.php?image=thename.png <?php /* start of the script */ $file_path = "/new/path/images/"; $file_name = basename($_GET['image']); if( file_exists($file_path . $file_name . ".gz") ){ header("Content-Encoding: gzip"); header("Content-type: image/png"); $content = file_get_contents( $file_path . $file_name . ".gz" ); echo $content; } else { echo "The file <i> $file_names </i> does not exist."; } /* end of the script */ ?> Maybe you want to control if the client does support the gzip compression, so u can use it: <?php if( eregi("gzip",$_SERVER['HTTP_ACCEPT_ENCODING']) ){ /* the script outputs the headers and the gz file content, as show_image.php script does */ } else { echo "Your browser does not support gzip compression. Update it."; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.header.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51482 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51482&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51482&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51482&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51482&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51482&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51482&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87292) next »