PHP How to ZIP multiple files located in different paths? - php

I have 16631 files hosted in a webserver, 2719 of them are text files that contains a list of specific files located on the server.
Using PHP, is possible to create a ZIP for each text file?
could be the text file name as ZIP file name?
I want to keep the same directory structure in the ZIP file.
Thanks in advance.

Taking the suggestion from Jeff Hines, you could use the ZipArchive class to create the zip.
In Pseudo code
Get List of Text Files in your folder
Read Text file and get list of files to add to zip
Using ZipArchive add each listed file to your new zip file.
Write flag to specify you've done this file.
You might need to run it on 10 files at a time since it may time out.

Related

PHP zip all image in specific file and generate a download link

I was searching for this but i can't find anything like this.I'm new to PHP, I want to have a backup of all my pictures in specific directory.
I want when i click on link it collect all the images in that directory and compress them into a zip file, then it give me a download link for them.
I saw an answer before for how to (download multiple files as zip in PHP) but i don't know how to get all the images full names in this directory and merge them with the commands for zipping
I wish that's possible.

how to avoid duplicate filename in wordpress

As we all know wordpress stores your uploaded files (for me,it's just JPG files) in a folder named "uploads" under "wp-content". Files are separated into folders based on year and month.
Now i want to copy every file from every folder into a single folder on another server (for some purposes). I want to know, does wordpress rename duplicate files? is it possible that my files be overwritten on the new server?
If yes, how can i avoid this? is there a way to make wordpress rename files before storing them?
You can scan your uploaded file folder and you have to options:
1.- Set a random name for each file
2.- Set a name convention including path and file name, for example: my_path_my_filename.jpg
By the way your file wont be overwritten cause is another server
This question seems about export/import...
Check exported XML (WordPress eXtended RSS file format), you can download all media URLs at <wp:attachment_url> tag... Use any XML parser.
Example without parser, at terminal:
cat exportedSite.xml | grep wp:attachment_url
will list all URLs. Each parsed URL can be downloaded by curl or wget.
If you whant to restore the XML backup, change (only) the URLs of the wp:attachment_url tags by the new repo URLs

Create ZIP/RAR files with only last modified files between date (WINDOWS)

I have modified some php code files which are part of a project that lives in a directory with subdirectories. Now I'd like to send a zip file which contains only the files that were modified last to another person. Like:
/c/index.php
/c/out/inc_out.php
/sales.php
Is there an easy way to select a date range and create a ZIP/RAR archive with the latest modified files? I'm on Windows.
Why using a script for this task? WinRAR supports such tasks directly.
Start WinRAR.
Navigate to the folder with the modified files to compress into a ZIP or RAR archive file.
Click on command Add.
Select the tab Time.
On list item Include files select either Newer than or Modified after.
Enter the appropriate time values according to the selected option.
Click on button OK.
WinRAR adds to the archive now only files with a last modification time according to the specified time values.
See help of WinRAR or file Rar.txt in program files folder of WinRAR if creating the ZIP/RAR archive file should be done from command line. There are explained the command line options -ta<date> (modified after) and -tn<time> (newer than).

Can back up specific files automatically from FTP to a specific folder using PHP?

I have lots of backup files in my FTP.
The file name like : index.php.bk-2013-12-27
I want to back up those files to the folder named /backup/
so inside of my httpdocs folder looks like this.
index.php
backup/index.php.bk.2013-12-27
the following both methods are fine to done this.
01. if any file contain name .bk that should be backed up automatically to the folder backup
or
02.
create a text file named backup_move.text that file contains the
paths of files that need to be copied and placed it into the httpdocs folder.
then the php script extract those file path from the
backup_move.text and sync the files to the folder named backup
How can I do this with some php coding.?
Any help will be very much appreciated.
It can be done (Both solutions).
But you need to tell if the solution (01) need to be recursive or Not. I suppose you know php has got a "time" to run (standard are 60 seconds), so you know that the file you need to backup cannot require more then 55 seconds to get a backup.
You can try and use the next link, it will backup completly a site, db and file and put it into a zip file. It need to be configured a little, but it can help.
http://www.starkinfotech.com/php-script-to-take-a-backup-of-your-site-and-database/

adding remote files to a zip file

Is there a way to add files to a zip file from another server with php's zip extension? ie.
addFile(array('localfile.txt,'http://www.domain.com/remotefile.txt'))
//(that obviously does not work)
I suppose I can download the files to a temporal folder and then add them to the zip file, but I was looking for a more automated solution or a function already made
use file_get_contents() and ZipArchive::addFromString()
$zipArchiveInstance->addFromString($filename, file_get_contents($mediaUrl));
This writes the contents fetched remotely straight into your php object (no need to write/read temp file)
It's not hard to read remote files in PHP.
file_get_contents("http://example.com/remote.txt");
Or to copy them locally:
copy("http://example.com/remote.txt", "/tmp/local.txt");
Whichever way you do it, the contents are going to have to be transferred to a local temp folder or memory before you can do anything with them.
Fetch them with cURL, add them from TEMP directory.

Categories