Jump to content

php file/folder zipping


jay3ld

Recommended Posts

Hello,

I am trying to figure out how to insert/create folders into a zip created by php and enter files into that folder. I never used php zip functions or anything like that So I am running off what I read around.

Basicly if you want to know what I am trying to do is after my website gets backups of each of my databases in mysql and put them into a folder I want to zip the folder up and then mail it.. I can get the backups and mail files but its the zip part I am trying to figure out how to do.
The reason I am trying to do this is my mysql databases are getting so big its starting to get hard to open one big text file when I need to get something that I lost back into my mysql database. So doing multiple Files for each of my databases (and optional for each table in database when I need to know that) should help me out with opening files..

This is what I wrote as a test..
In the folder there are 3 files like this
database1.sql
database2.sql
database3.sql

[code]
<?php

$path = '/home/user/testlocal/public_html/Mysql-backups/backups';

//Open the Direcotry were the files are saved.
$dir_handle = opendir($path) or die("Unable to open $path");

//Read the Direcotry.
while ($file = readdir($dir_handle))
{
//Ignore any files starting with . or index
    if(substr($file, 0, 1) == '.' || substr($file, 0, 5) == 'index')
        continue;

//Get the Extension out of the name and test it..
if(substr($file, -3, 3) == 'sql')
$files[$i++] = $file;
else
        continue;
}

//Open the file
$gz = gzopen('DatabaseBackups.gz','w9');

//Instert Into the zip file. Repeating process for each.
for ($a = 0, $i => $a, $a++)
gzwrite($gz, $files[$i]);

//Close it up.
gzclose($gz);
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/28400-php-filefolder-zipping/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.