note 51482 deleted from function.header by tularis

From: Date: Fri, 20 Apr 2007 14:56:47 +0000
Subject: note 51482 deleted from function.header by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-125670@lists.php.net to get a copy of this message
Note Submitter: snagnever at gmail dot com ---- 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."; } ?>

« previous php.notes (#125670) next »