Making a directory a zip file

I have a page named zip.php
There is a directory named “dir” in the same directory.with the zip.php.
Ttwo files named “index.php” and “test.php” are inside the directory .

I like to make the directory “dir” and the two files inside the direcotry a zip file named zipDir.zip.
The zip.php has the code below for making the direcoty “dir” a zip file.

<?php 

declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', '1'); 

// Enter the name of directory 
$pathdir = "dir/";  
  
// Enter the name to creating zipped directory 
$zipcreated = "dirZip.zip"; 
  
// Create new zip class 
$zip = new ZipArchive; 
   
if($zip -> open($zipcreated, ZipArchive::CREATE ) === TRUE) { 
      
    // Store the path into the variable 
    $dir = opendir($pathdir); 
       
    while($file = readdir($dir)) { 
        if(is_file($pathdir.$file)) { 
            $zip -> addFile($pathdir.$file, $file); 
        } 
    } 
    $zip ->close(); 
} 

but the result of the code above is the following.

How can I fix the Fatal error?

You tell your code to include the ZipArchive class file, whereever you’ve put it.

AFAIK it may be more a compile thing
https://www.php.net/manual/en/zip.installation.php

Linux systems

In order to use these functions you must compile PHP with zip support by using the –enable-zip configure option.

Or maybe it’s PECL ?

Installation via PECL

1 Like

Oh sorry. brain fart.

Yes, you’ll either compile with it or enable it in php.ini (if using Windows)

I am afraid that I didn’t tell the environment it is run on Windows and PHP Version 5.2.12

Would you, please, rephrase it?

What does it mean by AFAIK?

Oh, on Googling I found that AFAIK means “As far as I know.”.
I think it’s good abbreviation. Thank you.

Does it also need not only Linux but also Windows?

Hi Joon,

Is this thread about solving your real problem of transferring files from your old php5 server to your php7 server that was discussed in your other thread? If so, you are going about this the hard way, but on the other hand, you are learning new things which is always a good thing. :grinning:

Sometimes it gives me frustrated.

If the important thing is to just transfer files, then FTP or networking your computers will be the easiest fastest way to get there, FTP being the easiest.

No. The operating system doesn’t really matter, but it does matter on how you installed PHP. If there’s a problem with the zip dll file not loading, then your PHP configuration is messed up whether you installed that through a 3rd party program or installed the binaries yourself.

As many have already suggested, you should be using a more recent version of PHP. If your live server is running on PHP 7, it doesn’t make sense for you to be using PHP 5 on your development device.

Unfortunately trying to transfer files from PHP 5 source to PHP 7.

As previously mentioned in another topic a PHP 5 Server located bedroom and OP wants to transfer files to a PHP 7 Server in the living room. Currently using a thumb-drive to manually transfer files.

Yeah. It still doesn’t make sense to be running PHP 5 on any server as of currently. There are plenty of ways to upgrade PHP. The main problem with doing something like this is compatibility issues. If the local server is running on PHP 5 and files get transferred to the one with PHP 7, most likely those files will break because some files may have deprecated functions. Then if the OP edits the files on the server with PHP 7 to comply with PHP 7 and transfers the files back, now it’s also going to break the local PHP 5 server as well since those files may have more up-to-date functions that may not even exist in PHP 5.

My point is, just stick to using 1 version of PHP on all machines to avoid any of this. I run PHP 7 on all of my Macs even my “remote” Mac Mini that’s supposed to emulate a live PHP server running PHP 7.

That’s true.

Maybe it is possible. but I am very afraid of the upgrading might be destroying my old projects in the old server.

if it works in PHP5, it usually works in PHP7.
if not, I like to make it works with the code below.

if (PHP_VERSION ] '5.4') {
} else {
}

if it is impossible in PHP5, I will give up.
But if there is a little possibility, I stay in hungry to eat it.

[off-topic]
do you have internet access on both servers?

What is the directory size of the files on the PHP 5 Server?

Did you try creating a Free Web Hosting account? Most have at least 1 Gb Free. Is that enough for your needs?
[/off-topic]

Yes, they have internet access. it has a internet real IP each.

2 GB might be enough at the moment.

No, I didn’t yet. I will try to create a Free Web Hosting account later when I am ready.

1 Like

What did you use to install PHP?

That’s never going to work because you’re not using any comparison operators.

It was some years ago.
I don’t remember how I installed it.
It was one-click installation for Apache, PHP, mySQL and phpMyAdmin.
I was so happy because I installed it successfully.
After that I work with it for some years, but I completely forget how to install it and
where I downloaded the one-click program.

When I download Xubuntu, Apache, or something these days.
I write the installation process of major parts downt for installing it again.

I am sorry, it was typo of the below.

Which operating system did you do it on? I’ve created a whole topic relating to installing PHP on Mac, Windows, and Linux.

When I installed the one-click Apache_PHP_mySQL_setup, my O/S was XP.
Now it is upgraded to Window10

Yeah. The combination doesn’t really make a lot of sense. What you want to do is emulate a local remote server as closely as a live server. Majority of live servers run on Linux (either centOS or Ubuntu) so it doesn’t make sense to use Windows as a primary OS for your local remote server. But nevertheless, what I would do in your situation is re-install PHP using a more recent version through the binaries. This should be able to fix your ZipArchive issue since the zip dll should be included in those files.

I can re-install it and make a new server(Xubuntu, apache, PHP, mySQL and phpMyAdmin) now becaue I have the record of installing and setting process on my note.
But I cannot re-install it on the old server(PHP5) because I am afraid that the old project in the old server might be possibly destroyed.

Does it mean that they installed one by one intsead of by one-click?

if the quote above means each installation of apache, php, mySQL,
the new server is installed through the binaries. but the old server is not installed through the binaries.