Posts Tagged ‘php’

Get a Website root, Directory root and File root from PHP

January 20, 2011

If you want to see what root leads to your file, or if you want to grab breadcrumb links dynamically, you might find the following snippits useful. They will (respectively) echo the current site root, the current directory root and the complete root up to and including the current file name.

echo "Get current site root:";

echo "Get current site root & current directory name:
echo dirname(__FILE__);

echo "Get current site root, current directory name & current file name:


Unzip Files on a Remote Server

January 9, 2011

A really handy timesaver is the the ability to upload a single zip file, rather than hundreds of tiny files, and then unzipping it remotely. This saves time on uploading and minimises the possibility of corruption or failed uploads for the odd file buried deep in an obscure directory.

  1. To achieve this, create a blank html file and save it as something like unzipfiles.php
  2. Between the <body></body> tags, paste the following: <?php system(‘unzip’); ?>
  3. Replace the with the name of your zip file and upload the new page and your zip file to the same directory
  4. Access unzipfiles.php through your browser and the decompression should take place, expanding the contents of your zip file into your remote directory

I tested this with a small zip file which worked fine. With a larger file however (the js directory of Magento), I got a “The operation couldn’t be completed’ message in the Activity window of the browser. When I checked the remote directory, it seemed to have unpacked itself anyway – but this only presented the structure of the directories without actuall unpacking the contents – so this didn’t work.

I suppose it ultimate depends on what host you are using. Small files good, big files bad.