PHP File Directory Script with folder sizes

A new resource for customers – the Website File Explorer. Here’s how it came about.

What it does

The item lists the files and folders in a customers webspace, giving information such as file size, modification time, folder structure and size, all in a responsive, attractive layout.

Based on the script created by Hal Gatewood at http://halgatewood.com/free/file-directory-list/ we made a modification to show the folder sizes and give a total for the space used entirely.

screenshot of Free PHP File Directory Script showing Folder content size
Free PHP File Directory Script showing Folder content size

The single-file script can be placed in a web directory and loaded in a browser. It uses scandir to locate all the contents recursively, then filesize to get the properties of each item.

Responsive, Dynamic, Modern

The script also displays a nice icon for each type of file, and the last modified timestamp.

Folders are shown initially closed but a simple click expands them dynamically to reveal the contents.

Putting the Customer in Control

The script is used as a report for our web hosting customers, to give them more information about their accounts.

Most hosting control panels show disk quota and usage, but we were asked by customers to break down the usage in detail, so that they could get an idea where the space was being used. From personal experience we know webspace gets used over time for all sorts of random things – obsolete projects, testing space, a handy spot to dump that file you need to transfer one time only….

We had been providing this information manually, using the linux du‘ command. This has useful parameters such as –human-readable and –max-depth which made it ideal. However translating this function into a customer-facing tool in a safe and secure way meant a different approach – in our case using PHP.

We continue to use ‘du’ “under the hood” to provide a daily report to customers via our customer portal. Automatic warnings are generated in case a customers is getting close to their quota.

How big is that Folder in the Window?

One interesting thing we found is the different ways that file and folder sizes are calculated. There is also some differences in parameters for du (apparent sizes, rather than disk usage) that had to be taken into account when comparing PHP’s method of calculating file space usage with Linux’s (and our FTP server software).

We display the results in human-friendly units based on one Kilobyte being 1024 bytes.

Download Script

Download the script here: file-directory-size.php.txt

Remove the .txt extension and upload to your webserver.

Caution: This script will display the names (at least) of all files in your site. Therefore caution should be used before putting it in a public location. Our use of this script is tightly locked down so that it is safe and secure to use.

We would not recommend this script is used at all where register_globals is active (e.g. older php versions).


With thanks to the original creator, Hal Gatewood and user khanvani on fiverr.com

Passing data from PHP to JavaScript · A Beautiful Site

Source: Passing data from PHP to JavaScript · A Beautiful Site

 

Ever needed to send a PHP variable, array, or object to JavaScript? It can get complicated trying to escape the output properly. Here’s a way that always works—no escaping necessary.

Passing data from PHP to JavaScript

Have you ever needed to send a PHP variable, array, or object to JavaScript? It can get complicated trying to escape the output properly. Here’s a way that always works—no escaping necessary.

Let’s say we have the following variable in PHP:

  • $name = ‘Bob Marley’;

And we want to pass it to a JavaScript variable called name. Here’s the trick:

  • echo ‘<script>’;
  • echo ‘var name = ‘ . json_encode($name) . ‘;’;
  • echo ‘</script>’;

Using json_encode(), you’ll always get a properly formatted JavaScript object.

The Web Design Trends Dominating 2015 and How WordPress Stacks Up – WPMU DEV

Which web design trends have come to define 2015? And more importantly, is WordPress keeping up? We scrutinized a whopping 200 websites as part of an exhaustive search, revealing some obvious insights and a few surprises along the way.

Source: The Web Design Trends Dominating 2015 and How WordPress Stacks Up – WPMU DEV

So Your Client Wants a WordPress Slider? Here’s What You Need to Know

Whether you love them or hate them, sliders are still a popular feature of many free and premium themes. It’s not too difficult to see why: they’re eye-catching and draw attention to key information on your site. Despite the pros, there are many cons to using sliders. Here’s our verdict on whether you should use sliders or not.

Source: So Your Client Wants a WordPress Slider? Before You Cringe, Here’s What You Need to Know

Old-skool slider - not responsive, not accessible...
Old-skool slider – not responsive, not accessible…

We love a slider so we don’t think they’re going to disappear so soon.

2020Media Can Handle Stephen Fry

Recently a site hosted by 2020Media.com was given a mention on Stephen Fry’s Twitter account.

Commonly known as the “Stephen Fry Effect”, this can seriously test a hosting platform. His team had warned our client that this can result in up to 5000 hits per second.

They go on to say:

When Stephen tweets a URL to a given website, up to 10000 people will attempt to visit that website within half an hour. Very few websites can manage that intense traffic as the majority of it is within the first few minutes. Your website must be able to capable of taking 5000 hits per second in order to be able to stay live once Stephen’s tweeted.

Many website providers, particularly those that utilise shared servers,  will simply say “Yes it is fine”. You must double check with you technician that this is the case.

Well 2020Media is not one of the many, and we came up with a solution that we felt confident would be able to handle the traffic.

2020Media provided a Varnish cache server for client Creative Future recently to make sure their site was “Stephen Fry Proof”.
As you can see from the stats screengrab below, their site had a big increase in traffic on the day of the tweet, but no problems were seen at all.

the "Stephen Fry Effect" at client Creative Future
the Stephen Fry Effect

The site registered a 370% increase in visitor traffic, and more importantly, a big increase in the number of submissions to the Creative Future Literary Awards.

From a social media perspective, the tweet itself was favourably received by followers and influencers on Twitter and provoked a quick discussion by followers around the Twitter account name of the Creative Future Literary Awards!

Stephen Fry's tweet about CF Literary awards
Stephen Fry’s tweet about CF Literary awards

This could have been enhanced with a photograph, as this is proven to boost engagement. The tweet gained an average amount of retweets and favourites for a post of this type.

2020media is regularly deploying cache servers. Typically there are two types:

  1. Popular websites that get a lot of traffic all year round. A cache server offers two main benefits: a) Performance (speed of page load, responsiveness) of the site is increased. b) lower costs for the client versus increasing the traditional web server / database infrastructure.
  2. Ordinary websites that experience a periodic or one-off high volume of visitors. This can be for a particular event, or as in this case-study, thanks to a link from a highly popular site. 2020Media provides the caching server for a limited period of time to cope with the load, then returns the site to normal.

In all cases we take full ownership and set up everything for the client. Performance is closely monitored throughout and any problems responded to by fully trained engineers within minutes.

To enquire about our services, please see www.2020media.com, or call us on 0330 010 2020.