Skip to content
Advertisement

Zip files in a directory use part of URL as file name

I use a php file to created zip archive of all jpg files in a folder and make it available for download.

Here is the script:

JavaScript

I was wondering if it is possible to use part of url as archive name? My URLS look like this:

JavaScript

I want the archive name to be Pictures-Album-CustomText.zip

Advertisement

Answer

You have a couple of options:

Option 1: Using a combination of $_SERVER['PHP_SELF'], substr(), and str_replace().

Option 2: Using a combination of $_SERVER['PHP_SELF'], rtrim(), explode(), and count().

1st option, broken down:


JavaScript

JavaScript

2nd option, broken down:

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement