Creating a ZIP archive in PHP. Default appearance of WordPress archives In development of the topic

Here are the most important news items we have published in 2008 on the site.


Update (December 6th): Added missing zip security fix

There have been a great number of other additions and improvements since the last alpha, but here is a short overview of the most important changes:

  • (documentation has been updated to the current state)
  • ext/msql has been removed, while ext/ereg will now raise E_DEPRECATED notices
  • ext/mhash has been replaced by ext/hash but full BC is maintained
  • PHP now uses cc as the default compiler, instead of gcc
  • A number of bug fixes to ext/pdo, ext/soap, the stream layer among others

Several under the hood changes also require in depth testing with existing applications to ensure that any backwards compatibility breaks are minimized.

We would love developers, designers, managers or anyone else with an interest in the PHP programming language to join us for what promises to be an awesome event at a very reasonable rate:

  • Standard tickets: £60.00
  • Early bird (until 8th November): £50.00
  • Concessionary tickets: £35.00

* Confirmation with your company's letter head
**With Student ID. Limited seating available

THIS IS A DEVELOPMENT PREVIEW - DO NOT USE IT IN PRODUCTION!

The purpose of this alpha release is to encourage users to not only actively participate in identifying bugs, but also in ensuring that all new features or necessary backwards compatibility breaks are noted in the documentation. Please report any findings to the or the .

There have been a great number of other additions and improvements, but here is a short overview of the most important changes:

  • (documentation maybe out dated)
  • Addition of the , (phar is scheduled for some more work a head of alpha2), and extensions
  • Optional cyclic garbage collection
  • Optional support for the MySQLnd replacement driver for libmysql
  • Windows older than Windows 2000 (Windows 98, NT4, etc.) are not supported anymore ()
  • New syntax features like , limited GOTO, ternary short cut "?:"

Several under the hood changes also require in depth testing with existing applications to ensure that any backwards compatibility breaks are minimized. This is especially important for users that require the undocumented Zend engine multibyte support.

Our top submitter Felix De Vliegher has actually committed his last submissions himself since, based on the high quality of his submissions, he has been granted commit rights to the PHP repository. We have not heard back from all participants, but we encourage everyone to blog about their experience and provide us with feedback on how to improve future events.

Now better late than never, here are the 10 winners of the promised elePHPant raffle sponsored by Nexen. Note that Felix asked me not to include him in the raffle, since he is already herding quite a number of elePHPants at home.

  • Eric Stewart
  • Håvard Eide
  • Marc Veldman
  • Michelangelo van Dam
  • Rein Velt
  • Rob Young
  • Sami Greenbury
  • Sebastian Deutsch
  • Sebastian Schürmann
  • Stefan Koopmanschap

We will provide Nexen with the email addresses of the winners, so that they can arrange to get the elePHPants shipped. Also for those people wondering, you can continue to submit tests on the . A bit thank you to all participants and TestFest organizers! Without the countless people that helped organize local events, implement the infrastructure and submissions reviewers, the TestFest would have obviously not worked out as well as it has. We will surely do similar events in the future based on the great success of TestFest 2008.

Security Enhancements and Fixes in PHP 5.2.6:

  • Fixed possible stack buffer overflow in the FastCGI SAPI identified by Andrei Nigmatulin.
  • Fixed integer overflow in printf() identified by Maksymilian Aciemowicz.
  • Fixed security issue detailed in CVE-2008-0599 identified by Ryan Permeh.
  • Fixed a safe_mode bypass in cURL identified by Maksymilian Arciemowicz.
  • Properly address incomplete multibyte chars inside escapeshellcmd() identified by Stefan Esser.
  • Upgraded bundled PCRE to version 7.6

When you need to quickly download website sources from a server, even a relatively fast SSH tunnel does not provide the required speed. And you have to wait for a very, very long time. And many hosting providers do not provide this access, but force you to settle for FTP, which is many times slower.

For myself personally, I have identified a way out. A small script is uploaded to the server and launched. After some time, we receive an archive with all the sources. And one file, even via ancient FTP, downloads much faster than a hundred small ones.

Previously on the pages of this blog, the zipArchive library. However, then it was a question of unpacking the archive.

First, we need to find out if the server supports zipArchive. This popular library is installed on the vast majority of hosting sites.

The library is strictly limited by php and server parameters. Huge databases and photo banks cannot be archived. Even the bases of the good old 1C program for accounting. It would seem that they should only contain text data. But no.

I advise you to use the library only when archiving relatively small sites with a huge number of small files.

Let's check if the library is available to work with

If (!extension_loaded("zip")) ( return false; )

If all is well, the script will continue executing further.

A small offtopic for such checks. Checks should be done this way, avoiding large structures with nested parentheses. This way the code will be more atomic and easier to debug. Compare

If(a==b)( if(c==d)( if(e==f)( echo "All conditions met"; )else echo "e<>f"; )else echo "c<>d"; )else echo "a<>b;

and this code

If(a!=b) exit("a<>b); if(c!=d) exit("c<>d); if(e!=f) exit("e<>f); echo "All conditions met";

The code is nicer and does not grow into huge nested structures.

Sorry for being off-topic, but I wanted to share this find.

Now let's create an object and an archive.

$zip = new ZipArchive(); if (!$zip->open($destination, ZIPARCHIVE::CREATE)) ( return false; )

where $destination is the full path to the archive. If the archive has already been created, then the files will be added to it.

$zip->addEmptyDir(str_replace($source . "/", "", $file . "/"));

where $source is the full path to our category (which we initially archived), $file is the full path to the current folder. This is done so that the archive does not contain full paths, but only relative ones.

Adding a file works in a similar way, but you need to read it into a string first.

$zip->addFromString(str_replace($source . "/", "", $file), file_get_contents($file));

At the end you need to close the archive.

Return $zip->close();

I don’t think there’s any need to explain how to go through all the files and subdirectories in a folder. Google it, something like Recursive traversal of folders in php

This option suited me

Function Zip($source, $destination)( if (!extension_loaded("zip") || !file_exists($source)) ( return false; ) $zip = new ZipArchive(); if (!$zip->open( $destination, ZIPARCHIVE::CREATE)) ( return false; ) $source = str_replace("\\", "/", realpath($source)); if (is_dir($source) === true)( $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST); foreach ($files as $file)( $file = str_replace("\\", "/", $file); // Ignore "." and ".." folders if(in_array(substr($file, strrpos($file, "/")+1), array(".", ".."))) continue; $file = realpath($file ); $file = str_replace("\\", "/", $file); if (is_dir($file) === true)( $zip->addEmptyDir(str_replace($source . "/", "" , $file . "/")); )else if (is_file($file) === true)( $zip->addFromString(str_replace($source . "/", "", $file), file_get_contents($ file)); ) ) )else if (is_file($source) === true)( $zip->addFromString(basename($source), file_get_contents($source)); ) return $zip->close(); )

Yesterday on the forum I was asked about creating ZIP archives in PHP. I thought a little and realized that this topic would be interesting to a large number of people, because ZIP archiving in PHP a very popular topic. And in this article I will show an example, how to create a ZIP archive using a PHP script.

Let me give you an example right away creating a ZIP archive, and then I will carefully comment on it:

$zip = new ZipArchive(); //Create an object for working with ZIP archives
$zip->open("archive.zip", ZIPARCHIVE::CREATE); //Open (create) archive archive.zip
$zip->addFile("index.php"); //Add the index.php file to the archive
$zip->addFile("styles/style.css"); //Add the file styles/style.css to the archive
$zip->close(); //Finish working with the archive
?>

As a result of executing this script, you will see ZIP archive, which will have a file in its root index.php, and a directory will also be created styles, which will contain the file style.css. I think this is all obvious and logical. And now I’ll comment on what we did with you:

  • Created an object ZipArchive using the constructor.
  • Created an archive using the method open() object ZipArchive. We have passed on the name of the archive ( archive.zip) and a constant ZIPARCHIVE::CREATE, which reports that if the archive does not exist, then it must be created.
  • Method addFile() adds files to the archive. First we added the file " index.php", which is located in the same directory with the script. Next we added the file style.css, also indicating the correct path to it relative to the script.
  • Method close() finishes working with the archive. Always run it to free up computer resources and also to avoid a variety of problems associated with the operation of this script and other scripts that need access to this archive.

In this simple way you can automatically create ZIP archives using PHP. In the next article we will discuss with you, how to extract zip archive via php.

The Internet Archive offers over 15,000,000 freely downloadable books and texts. There is also a collection of that may be borrowed by anyone with a free site account.

Alternatively, our portable Table Top Scanner can also be purchased and used on-site within libraries and archives. To read more about our TT Scribe, please visit.

Since 2005, the Internet Archive has collaborated and built digital collections with over 1,100 Library Institutions and other content providers. Partnerships include: , the and the . These collections are digitized from various mediatypes including: , and a wide variety of . Significant contributions have come from partners in North America ( and Libraries), and , representing more than 184 languages.


The Internet Archive encourages our global community to contribute physical items, as well as uploading digital materials directly to the Internet Archive. If you have digital items that you would like to add to the Internet Archive, please a new item using the uploader interface. Click here to apply the specific creative commons license Creative Commons license to communicate how the material can be used.

For donation of physical books or items, please contact info@site


Free to read, download, print, and enjoy. Some have restrictions on bulk re-use and commercial use, please see the collection or the sponsor of a book. By providing near-unrestricted access to these texts, we hope to encourage widespread use of texts in new contexts by people who might not have used them before.

It is clear that it is easier for template creators to use standard functions and WordPress template tags to display standard views of all site pages, but this creates a uniform appearance and a feeling of transition to the same pages of the site.

I’ll show you right away what we get as a result.

Type of WordPress archives: archive of categories before changes
Archive of sections with removed thumbnails and a link for more details.

Important! Since this task is solved by changing the template code, before work we do (database + site files). In addition, we make two copies of the working template, one for editing, the second for restoring incorrect editing.

Changing the appearance of WordPress archives

To change the appearance of WordPress archives, you need to find, or rather, determine which file in your working template displays archives. In most templates, all archives are output in a single file, it is called (archive.php).

I repeat, to be safe from losing the site, we do not use the editor in the site’s administrative panel, but rather edit the previously made backup copies of the template files.

In a text editor (such as Notepad++), open the archive.php file and start editing. In the archive.php file (at the end of the file) we look for a function that displays the archive blog:

Name is the name of the file that is used to output the archive blog.

The first idea for completing the task is simple: we need to change the code of the file that outputs archives (content.php), namely, remove several functions from it, and thereby change the appearance of all the site’s archives (categories, authors, dates, etc.).

But the question arises, if we change the code of the template file, it will return to its previous state after the first update of the template, we do not need this. Therefore, we will not edit the content.php file, but copy it and create our own file under a different name, for example content-cat.php and edit it.

We are looking for a function in the file that displays thumbnails. The thumbnail function will be at the top. We remove the thumbnail output.

orand remove the line with ‘Read More’, ‘template name’.

We save the created and edited content-cat.php file and upload it to the site directory in the working template folder. This file will appear in the site's administrative panel on the Appearance→Editor tab.

Let's move on to the second step. In the file that outputs archives (archive.php), change the file name content to content-cat .

We save and look at the result. If something is wrong, the system will show an error, an error file and an error line. To correct the error, return the saved backup template files to their place and repeat everything again.

Advice. If you want to read more about template tags and standard WordPress features, pay attention to this site: https://wp-kama.ru. This is not an advertisement or even a link, this site is clearer than the official WordPress site in the template and feature tags section.

In development of the topic

In my opinion, the topic of announcements on WordPress sites requires continuation. In the coming posts, I will talk about the topics: and.

WordPress Codex

Hidden text

the_post_thumbnail function

Function

the_post_thumbnail

Purpose

The_post_thumbnail function outputs the html code of the post thumbnail image, an empty value if there is no image.

Application

This template tag, the_post_thumbnail function, must be used internally

Usage

the_post_thumbnail(string|array $size = "post-thumbnail", string|array $attr = "")

Source

File: wp-includes/post-thumbnail-template.php

Function the_post_thumbnail($size = "post-thumbnail", $attr = "") ( echo get_the_post_thumbnail(null, $size, $attr); )

Options

$size (string/array)

The size of the thumbnail to receive. It can be a string with conditional sizes: thumbnail, medium, large, full or an array of two elements (image width and height): array(60, 60).

Default: ‘post-thumbnail’, that is, the size that is set for the current theme by the function set_post_thumbnail_size()

$attr (string/array)

An array of attributes that need to be added to the resulting html img tag (alt is an alternative name).

Default:

Example

" title= "_("permalink"), the_title_attribute("echo=0")); ?>"> !}get("layout", "imgwidth"), $SMTheme->get("layout", "imgheight")), array("class" => $SMTheme->get("layout","imgpos") . " featured_image")); if (!is_single())( ?>
mob_info