Re: Parsing and organizing files in folder with PHP question
| From: | Stefan A. | Date: | Wed, 17 Jul 2019 19:30:16 +0000 |
| Subject: | Re: Parsing and organizing files in folder with PHP question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-326852@lists.php.net to get a copy of this message | ||
Hi,
One way of doing this is with a command line script that you can run on the
server where your content folder resides. To that end I would recommend
reading through the following PHP manual links:
- https://www.php.net/manual/en/ref.dir.php
- functions for working with
directories: specifically opendir, readdir and closedir
- https://www.php.net/manual/en/book.filesystem.php
- functions for
working with the file system: specifically filemtime for determining the
file age, pathinfo for determining the file type by extension, file_exists
for determining if a file exists, copy and rename for copying/moving files
You could/should test on some sample data before to make sure you get the
desired outcome.
Also don't forget to backup your data :)
On Wed, Jul 17, 2019 at 8:20 PM Matthew Zand <dcwebmakers@gmail.com> wrote:
> Hi,
>
>
> I have a content folder on my website with more than few thousand images
> and videos. I want to write php code to do following:
>
> 1- Read all files on the folder
>
> 2- Remove all files that are older than 2 years ago
>
> 3- Loop through all content files to check file type and save them in two
> arrays (one for images and another for videos)
>
> 4- Merge new image array files with an existing image folder files but if
> duplicate exists, override the older version of file.
>
>
>
> What is best way to achieve this?
>
> --
> Best,
>
> DC Web Makers <https://blockchain.dcwebmakers.com/>
> Coding Bootcamps <https://coding-bootcamps.com/>
> 240-200-6131
> 301-327-8773
>