note 57357 added to function.gzwrite
| From: | quatrux at gmail dot com | Date: | Sat, 01 Oct 2005 09:57:55 +0000 |
| Subject: | note 57357 added to function.gzwrite | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96122@lists.php.net to get a copy of this message | ||
Here are some functions I wrote which might be useful for others to use.
<?php
function gzput_file_contents($file, $data) {
/* check if Directory exists */
if (is_dir($file)) {
return FALSE;
/* check if file exists and is Removed */
} elseif (is_file($file) AND !unlink($file)) {
return FALSE;
/* create new File with owner PHP */
} elseif (!touch($file)) {
return FALSE;
}
/* Open and Store Data to File */
$gz = gzopen($file, 'w9');
if (gzputs($gz, $data) === FALSE) {
return FALSE;
}
gzclose($gz);
return TRUE;
}
function gzget_file_contents($file) {
/* Check if is File */
if (!is_file($file)) {
return FALSE;
}
$gzfile = implode(gzfile($file));
return $gzfile;
}
gzput_file_contents('test.txt.gz', 'This is my Test Message');
echo mime_content_type('test.txt.gz'); // application/x-gzip
echo gzget_file_contents('test.txt.gz'); // This is my Test Message
echo file_get_contents('test.txt.gz'); // Compressed Data
?>
----
Manual Page -- http://www.php.net/manual/en/function.gzwrite.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57357
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57357&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57357&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57357&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57357&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57357&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57357&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57357&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57357&report=yes
Search -- http://master.php.net/manage/user-notes.php