Manage Server Hard Disk Using PHP

By  on  

PHP provides some sweet functions to manage the server's hard disk. Here's how to use them.

copy()

Copies a file from a source file.

$result = copy('original.txt','new.txt');

disk_free_space()

Returns the number of bytes remaining on the disk.

$free_space = disk_free_space('/');

disk_total_space()

Returns the size of the disk in bytes.

$total_space = disk_total_space('/');

file_exists()

Confirms whether or not a file exists.

$exists = file_exists('rubbish.php');

unlink()

Deletes a file from the disk.

$file = 'rub.txt';
if(file_exists($file))
{
	unlink($file);
}

For more information on file-specific functions, read Basic PHP File Handling — Create, Open, Read, Write, Append, Close, and Delete.

Recent Features

  • By
    7 Essential JavaScript Functions

    I remember the early days of JavaScript where you needed a simple function for just about everything because the browser vendors implemented features differently, and not just edge features, basic features, like addEventListener and attachEvent.  Times have changed but there are still a few functions each developer should...

  • By
    LightFace:  Facebook Lightbox for MooTools

    One of the web components I've always loved has been Facebook's modal dialog.  This "lightbox" isn't like others:  no dark overlay, no obnoxious animating to size, and it doesn't try to do "too much."  With Facebook's dialog in mind, I've created LightFace:  a Facebook lightbox...

Incredible Demos

Discussion

  1. Mittul Chauhan

    i didnt know that ..

    thanx for sharing

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!