Two little PHP scripts I use, and maybe you should too.

Tomasz Kowalski
3 min readOct 22, 2020

I wanted to introduce you to two small PHP scripts that I often use. Both are mainly used when working with Joomla! But I’m sure anyone can adjust it to other needs even with a little PHP knowledge.

Both scripts are tiny and meant to do one specific thing. Easy and effective.

The first file is universal; the second is prepared for Joomla! installations, but you can easily modify it if you know PHP to work with any similar folder structure.

copy.php — use it to transfer files between two servers.

Purpose: To transfer large files between two servers. I use it mainly to transfer Akeeba Backup backups between two servers. If you want to use it for this purpose — remember that you need to disable the .htaccess file (in: administrator/components/com_akeeba/backup) as it will prevent downloading the file if .htaccess is present.

This script lets you provide the source file and download it from a remote server to the server where the file is located. Mostly used for transferring large files between servers.

This is how the server to server PHP copy script file looks like

How copy.php works?

  1. Download the file from → here.

2. Upload it via FTP to the server where you want the file to be downloaded.

3. Edit the file and fill:

3a. In $source, provide the remote file full URL

3b. In $target, provide the target filename (file will be downloaded to the same folder where copy.php is)

4. Open your browser and fire up the file copy.php from your server

5. Wait a moment, and if all went fine, you’d see a “File copied” notification

That’s it; your file was copied.

tmpcleaner.php — use it to empty /tmp and /cache folders

Purpose: If you have many Joomla! installations in one folder (each Joomla! in its own folder), this script will help you empty /tmp and /cache folders in one go in all of these installations.

In tmpcleaner.php file, you can choose if you want to clean only /tmp or /cache folders' contents. You can also empty both those folders at once.

tmpcleaner.php script.
This is how tmpcleaner.php PHP script code looks like

How tmpcleaner.php script works?

  1. Download the file from → here.
  2. Upload it via FTP to the location where your Joomla! installations are located
  3. Edit the file and comment or uncomment lines 3 and/or 4

3a. scanAndClear(‘tmp’) — this line tells the script to empty the /tmp folders

3b. scanAndClear(‘cache’) — this line tells the script to empty the /cache folders

4. Open your browser, navigate to the URL where the file is located, and fire it up.

5. See files and folders deleted. Once the process is over, you’ll see a “Done!” message.

Screenshot of finished work of the tmpcleaner.php script

Thank you for reading! I hope you find these scripts useful. If you have any questions or something to add, let me know.

Just in case: you need to know what you’re doing with those scripts. I don’t take any responsibility for the possible damages (not really sure what could happen, but you never know).
If you don’t use it, delete the file.
These scripts work for us doing simple tasks, feel free to modify them, and customize to your needs.

--

--