Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

TutsPlus.com:
How to Zip and Unzip Files in PHP
Oct 24, 2018 @ 18:35:56

The TutsPlus.com site has a tutorial posted showing how to make use of the ZIP functionality in PHP to handle the compression and decompression of ZIP archives programatically.

Compressing files when transferring them over the internet has a lot of advantages. In most cases, the combined total size of all the files in the compressed format comes down by a nice margin. This means that you will save some of your bandwidth, and users will also get faster download speeds.

[...] One factor that can discourage you from compressing files or make the process very tiresome is the fact that you might be doing it manually. Luckily, PHP comes with a lot of extensions that deal specifically with file compression and extraction. You can use the functions available in these extensions to automatically compress files in PHP.

This tutorial will teach you how to zip and unzip (compress and extract) files to and from a zip archive in PHP. You will also learn how to delete or rename files in an archive without extracting them first.

The tutorial starts with the compression of files making use of the ZipArchive class to create a new instance, add files to compress and close it out to write the resulting archive. Next it shows the reverse, using the same class to create an instance and extraction path. There's also an example of using a loop for even more control of which files are included in the archive.

tagged: tutorial zip unzip introduction ziparchive archive compress

Link: https://code.tutsplus.com/tutorials/file-compression-and-extraction-in-php--cms-31977

Oscar Merida:
Creating ZIP files and streaming the response with Silex
Jan 19, 2018 @ 17:28:44

On his site Oscar Merida has shared a post showing how to create a ZIP file and stream the response in a Silex-based application using the DOMPDF library and PHP's ZipArchive functionality.

Creating a zip file is easy and Rob Allen has you covered on that front to get you started. I needed to do this to create a zip file of PDF files generated by Dompdf. It turns out, you can add files to a ZipArchive object without actually creating the file if you can get the contents as a string.

The post includes the code to create the DOMPDF instance, load the HTML and render the result. From there the ZipArchive takes over and creates the archive from the PDF result. Finally the code takes the ZIP archive as input and pushes it out with a custom header to tell the browser to download it and streams back the raw ZIP contents.

tagged: tutorial silex dompdf pdf zip archive silex stream download

Link: http://oscarm.org/2018/01/stream-a-zip-file-via-silex/

Zend Framework Blog:
Create ZPKs the Easy Way
Mar 22, 2017 @ 14:05:17

On the Zend Framework blog Enrico Zimuel has posted a tutorial showing you how to easily create ZPKs and package up your application for deployment on Zend Server.

Zend Server provides the ability to deploy applications to a single server or cluster of servers via the ZPK package format. We have offered zf-deploy for creating these packages from Zend Framework and Apigility applications, but how can you create these for Expressive, or, really, any PHP application?

They start by listing out some of the requirements you'll need to get started (the zip binary, Composer, etc). The tutorial then walks you through the setup including the contents of the .htaccess and deployment.xmlconfiguration files. It then walks through the installation of dependencies and actually creating the ZFK (via the zip binary). It wraps up with a simple example of the creation of a ZPK containing a single index.php file.

tagged: zendframework zendserver zpk zip package deployment tutorial

Link: https://framework.zend.com/blog/2017-03-21-create-zpks-the-easy-way.html

Remi Collet:
ZipArchive with encryption
Mar 03, 2017 @ 18:56:56

In this new post Remi Collet focuses on the use of the zip extension and using the ZipArchive functionality to create encrypted archives with PHP.

Point of the situation with the development of zip extension version 1.14.0 which implements support of encrypted archives.

This new feature implementation rely on libzip library new version 1.2.0. For now, only build using system library is supported for this new feature, but an update of the bundled library is planed. When everything will be validated, version will be released and merged in php sources (ext/zip), probably in PHP 7.2.

This development is in progress, nothing final, proposed methods still can change.

The tutorial shows how to get the package installed (via a clone of the GitHub repository) and how to work with encrypted archives, creating and reading their contents.

tagged: tutorial ziparchive zip extension encrypted

Link: https://blog.remirepo.net/post/2017/03/01/ZipArchive-with-encryption

Weebly Engineering Blog:
Streamed File Zipping and Downloading in PHP
Feb 06, 2017 @ 17:24:01

The Weebly Engineering blog has a new tutorial posted about streamed file zipping and downloading in a PHP based application. This allows the download to start even while the file is being compressed into a zip archive on the backend.

Did you notice that on Dropbox.com, you can select a folder and start downloading it while it’s being zipped? This on-the-fly zipping feature comes handy for both the user and the server?—?as a user you don’t have to wait until the files are zipped on the back end before the downloading starts, and it saves the server from creating a temporary zip file and deleting it afterwards.

[...] To implement this feature with PHP, we handle the zipping and streaming work on the back end using ZipStream. Assuming your files are on the server and can be loaded with file_get_contents given a path.

They include some of the details of the HTTP request format for the stream (as an attachment type) and how you can use the ZipStream package to quickly implement it into your code. They include a simple example of implementing it in a form, allowing the user to easily integrate it and work around some of the browser based security controls.

tagged: stream zip archive download tutorial zipstream tutorial

Link: https://medium.com/weebly-engineering/streamed-file-zipping-and-downloading-in-php-1fb59b0a5b79#.jop61kzc6

Ben Ramsey:
Composer: Missing Distributions for Explicit References
Jun 18, 2015 @ 15:14:31

Ben Ramsey has shared an interesting issue he's come across when installing packages via Composer where it installed a different version than expected when he ran an install. The problem turned out to be from an unexpected place.

For applications I control that are not distributed to the public, I like to hard-lock my Composer dependencies to a specific version. [...] Sometimes a library has updates that haven’t yet been released, and I need to use these right away. Composer allows me to specify the specific commit I want to use for a library. In this way, I can hard-lock a dependency to a specific state, even when there is not yet a release for the changes I need. This has worked well until today, when I tried to do a fresh composer install. After installing, one library contained files and methods that I did not expect. It turns out Composer was grabbing the HEAD of dev-master instead of the specific commit I referenced.

After some investigation into his "composer.lock" file's contents, he found the issue: a problem with the way that BitBucket handles the distribution zip files Composer requests. In his example, the zip file was of the HEAD on the repository, not of the specific commit (GitHub doesn't have this problem). His solution was using the (slower) "--prefer-source" option to grab the correct commit contents...not an ideal solution but it does what he needs.

tagged: composer missing distribution zip file explicit reference bitbucket

Link: http://benramsey.com/blog/2015/06/composer-missing-distributions/

Rob Allen:
Creating a zip file with PHP’s ZipArchive
Jan 15, 2014 @ 21:40:59

Rob Allen has a new post to his site today showing you how to create a ZIP file with the help of PHP's ZipArchive functionality. The latest versions would need to be installed as an extension (PECL) if they're not already there, but it makes creating the archives a lot simpler.

I recently had a requirement to create a zip file from a number of files created within my application. As it has been years since I last had this problem, I had a look around and discovered that PHP 5.2 has the ZipArchive class that makes this easy. ZipArchive is fully featured, but as I just wanted to create a simple zip file.

All it requires is a few short lines of code - one to open the archive itself, some to add in the files to compress down and another to close and create the file. It's a pretty simple process using this handy extension. Rob also included a bit of sample code showing how to send it out for download with the correct headers.

tagged: zip file archive create tutorial ziparchive

Link: http://akrabat.com/php/creating-a-zip-file-with-phps-ziparchive

WebSpeaks.in:
Extract the Content of Zip file Using PHP
Jun 13, 2012 @ 15:44:44

On the WebSpeaks.in site, there's a recent tutorial posted showing how you can extract the contents of a zip file from inside a PHP application.

Sometimes you may want the users on your site to upload the zip file and then check what are the contents of that zip file. In this article I will tell you how to extract the contents of the zip file. I temporarily extract the zip files to a directory and then delete it afterwards. You can chose to keep the extracted content if you want.

The tutorial walks you through the code, showing you how to use their "ZipArchive" class to grab the file, extract the contents and display a list of the "child files" inside it. You can see a live demo of it in action or just download the source and dive right in.

tagged: extract content zip archive list tutorial demo

Link:

PHPMaster.com:
Sending Emails with PHP
Oct 25, 2011 @ 01:08:52

In a new tutorial from PHPMaster.com Jason Pasnikowski takes a look at sending emails with PHP - an introduction to what the language offers and how it can be used to send an HTML version.

In most cases your installation of PHP will be capable of sending emails. If you are using a shared host, or if you installed PHP using a package management system like apt-get, more than likely you’re all set. You’ll really only need to worry about extra configuration if you’re compiling PHP from source or if you’re running it on Windows. In either case, there are plenty of resources available online to help you out. Because that’s all beyond the scope of this article, I’ll assume you’re set. If not, Google will be your friend.

He starts with a simple example using the mail function but quickly moves on to sending a multi-part email with an attached zip file and HTML content. He includes the all code you'll need and explains each part in detail so you'll know exactly what's going on.

tagged: send email tutorial html multipart zip file

Link:

PHPBuilder.com:
Working with Zip Archives in PHP
Apr 07, 2010 @ 13:44:54

On PHPBuilder.com today Octavia Anghel has written up a tutorial about working with zip archive files directly from PHP. The key is the Zip Archive extension that you can get from the PECL repository if you have a version older than PHP 5.2. Those on PHP 5.2 or higher already have it bundled in.

I explain how to manage Zip archive files in PHP using a number of demo PHP applications. You'll learn how to create Zip archives, add files and folders inside the archive from a string and from a given path, delete and rename files using their indexes and names and list the ZipArchive object details (number of files, filenames, comments, statusSys, etc.).

Complete code for the examples (along with a few screenshots) are included in the tutorial as well as a link to download the source to get you started even faster.

tagged: archive zip tutorial pecl extension

Link:


Trending Topics: