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
    6 Things You Didn’t Know About Firefox OS

    Firefox OS is all over the tech news and for good reason:  Mozilla's finally given web developers the platform that they need to create apps the way they've been creating them for years -- with CSS, HTML, and JavaScript.  Firefox OS has been rapidly improving...

  • By
    Designing for Simplicity

    Before we get started, it's worth me spending a brief moment introducing myself to you. My name is Mark (or @integralist if Twitter happens to be your communication tool of choice) and I currently work for BBC News in London England as a principal engineer/tech...

Incredible Demos

  • By
    CSS Filters

    CSS filter support recently landed within WebKit nightlies. CSS filters provide a method for modifying the rendering of a basic DOM element, image, or video. CSS filters allow for blurring, warping, and modifying the color intensity of elements. Let's have...

  • By
    CSS Ellipsis Beginning of String

    I was incredibly happy when CSS text-overflow: ellipsis (married with fixed width and overflow: hidden was introduced to the CSS spec and browsers; the feature allowed us to stop trying to marry JavaScript width calculation with string width calculation and truncation.  CSS ellipsis was also very friendly to...

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!