CruzIT
Saturday December 04, 2021 - 2:50:48 AM

Registered Linux User #440901    


 
Login    Register
Login Required

Create a gzip file in PHP

This is a how-to on making a gzip file out of a text file with PHP. (alternate GNU gzip page.)
Make a file called compreport.php (or whatever you want) and put it this in it:

<?php
// Name of the file we are compressing
$srfile = "sourcefile.txt";
//Find out if the file exists do the thing
if (file_exists($srfile)) {
// Name of the gz file we are creating
$gzfile = "compressedfile.gz";
// Open the gz file (w9 is the highest compression)
$fpp = gzopen ($gzfile, 'w9');
// Compress the file
gzwrite ($fpp, file_get_contents($srfile));
// Close the gz file and we are done
gzclose($fpp);
$varzfilename=$gzfile;
echo $gzfile . ' file was generated! ';
//create the file lastmod_varz.php
//then uncomment the following line
//include "lastmod_varz.php"; 
}
//if source file is missing or has the wrong permissions!
else {
    echo 'The source file ' . $srfile . ' does not exist!!! 
    The compressed file ' . $gzfile . ' was not created or appended!';
}
?>

Make a file called lastmod_varz.php and put it wherever you put your include files. The lastmod_varz file should have this in it:

<?php
$varzfile = $varzfilename;
$last_modified = filemtime($varzfile);
print("Last modified on ");
print(date("m/j/Y" . " @ " . "h:i:s:a", $last_modified));
?>

The lastmod_varz.php can be re-used wherever you want to show when the last modified time was for any file. Just assign the $varzfilename a value either a variable name or a quoted file name:

$varzfilename=$gzfile;
OR
$varzfilename="/reports/somefile.gz";

You could make all that an include page and put some styled <p class="coolpstyle"> tags around it.

If you would like some information on how to do something use the Contact Page. Someone will get back with you with an answer.

Page generated in zero point one two (0.12) seconds.

@ Active Member Project Honeypot  email addresses

This page was last modified on 09/1/18 @ 10:33:50:pm
This file name: info_php_gzip.php

Questions, Comments, Suggestions or Requests should be sent to:  ronnie@cruzit.com 

There have been  21581  Unique Visitors (IP Addresses) to this site.

Current users online : 13
Maximum users at a time : 50
Last 25 attacks have come from:
185.165.169.18
185.214.134.131
207.46.13.41
13.69.60.176
171.97.153.227
3.235.99.197
159.223.47.252
84.17.48.84
177.21.51.36
141.95.1.178
172.104.159.48
185.106.130.251
185.218.124.140
185.41.152.98
20.90.42.87
138.94.118.190
192.241.177.127
109.234.161.67
159.65.137.160
89.187.185.39
18.141.190.234
125.9.149.223
165.22.214.5
146.70.25.5
78.157.40.153

There are currently 25 unique IP addresses blacklisted.

Public cruzit.com Server Status
server online dbc001  db cluster service
 Is On-Line
server online www03  web service
 Is On-Line
server online www  web service
 Is On-Line
server online mx 08  mail service
 Is On-Line
server online www ha  F/O web service
 Is On-Line
server online mx 11  mail service
 Is On-Line
server online Primary  Client DNS
 Is On-Line
server online Secondary  Client DNS
 Is On-Line

©Copyright 2004-2021 - cruzit.com - Redd Enterprises™, Inc.,  All Rights Reserved.
Ubuntu® is a registered trademark of Canonical Ltd.
Linux® is a registered trademark of Linus Torvalds.
Apache® is a registered trademark of The Apache Software Foundation.
PHP® is a registered trademark of The PHP Group.
The MariaDB® a registered trademark of the MariaDB Corporation Ab.
MySQL® is a registered trademark of the Oracle Corporation Inc.
All other product and service names mentioned are the trademarks of their respective companies.

 

pretrial
pretrial
pretrial
pretrial
Let us know what you think! finance@homelandcomputersecurity.com