PHP Classes

PHP Emulated SQL Filesystem: Emulate a filesystem storing files in SQL database

Recommend this page to a friend!
  Info   View files Example   Demos   Screenshots Screenshots   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 62%Total: 421 All time: 6,384 This week: 488Up
Version License PHP version Categories
sqlefs 0.8.5MIT/X Consortium ...5.0PHP 5, Files and Folders, Emulators


This class can emulate a file system storing files in a SQL database.

It can connect to a given database using PDO and performs several types of operations with names very similar to DOS and Linux to make it work like a file system. Currently it can:

- Set the name of the currently emulated disk
- Change the current directory to a given path
- List files of given path
- Fetch information of a file
- Fetch information of all files with a given path
- Get subdirectories of a given directory
- Change the current directory to the parent directory
- Read or write to a given file
- Remove a file or a directory
- Copy a file to another
- Check if a file exists
- Set or get the owner of a given file
- Write a file with a given uploaded file contents
- Serve a given file for download
- Load or save serialized data to a file
- Resolve the path of file with given parameters
- Create, list and describe disk volumes
- Format, check the status, defragment, and backup a disk

Innovation Award
PHP Programming Innovation award nominee
April 2016
Number 5
Many applications need to store and retrieve files that need to be accessible by a cluster of Web servers.

One solution for this problem, is to store files, at least not very large files, in databases.

This class emulates a file system on a SQL database. It provides all sorts of commands to manage files, directories and disk with similar names to those used in Linux and DOS.

Manuel Lemos
Picture of Ryan Cole
Name: Ryan Cole <contact>
Classes: 1 package by
Country: United States United States
Age: ???
All time rank: 3478464 in United States United States
Week rank: 298 Up37 in United States United States Up
Innovation award
Innovation award
Nominee: 1x


# This script allows a user to make post their favorite color on the website.
# This program is a demostration of basic file handling methods in SQLEFS.
# See it in action at:

### This file just handles your login details and sets the volume. ###
require_once 'sqlefs_login.php';

### Or you could specify that stuff in your script like so ###
# require_once '../sqlefs.class.php';
# $efs = new efsclass();
# $efs->connect('mysql:mysql:host=localhost;dbname=myefsdb name pass');
# $efs->cd('c:/');

$showlen = 10; # show this many entries
$namelen = 25; # max length of name
$do = isset($_REQUEST['color']) ? 'post' : 'view';

### Set the current working directory. ###

# view comments
if ($do == 'view') {
$content = '<h1>Visitors Favorite Colors</h1>';

$content .= '
        <p>Enter your name and favorite color!</p>
        <form role="form" method="post" enctype="multipart/form-data">
        <input type="text" name="name" placeholder="Name" size="'
. $namelen . '">
        <input type="color" name="color">
        <input type="submit">

### Retrieve a listing of files and reverse it so newest are first. ###
$files = array_reverse($efs->ls());

# list each entry. We also reverse them to see newest first
foreach ($files as $file) {

### Load our file as serialized data. ###
$submission = $efs->load($file);

$content .= '<div class="name">' . $submission['name'] . '</div>' ;
$content .= '<div class="color" style="background-color: ' . $submission['color'] . '"></div>' ;

# post a color
if ($do == 'post') {
$content = '<b>Thanks for posting!</b>';
$name = htmlspecialchars( substr($_REQUEST['name'], 0, $namelen) );
    if (
$name === '') {$name = 'Anonymous';}
$color = htmlspecialchars($_REQUEST['color']);
$data = array('name' => $name, 'color' => $color);
$filename = crc32($name . $color);

### Save data in serialized format. ###
$efs->save($filename, $data);

# We intend to limit the number of entries we show...
    # SQLEFS orders file listings by oldest first by default,
    # so we'll just delete the first files in the listing
    # until we have the right number to show.

    ### Retrieve file listing. ###
$files = $efs->ls();

$trimcount = count($files) - $showlen;
    while (
$trimcount > 0) {

### Delete the file removed from the array. ###
$efs->rm( array_shift($files) );

$trimcount -= 1;
$content .= '<hr><a href="colorlog.php">view entries</a>';

.name {width: 200px;text-align: center;}
.color {width: 200px;height: 25px;}
<?php echo $content; ?>

  ExamplesExternal page  
  • console.png
  • fileman.png
  Files folder image Files  
File Role Description
Accessible without login Plain text file admin.php Example Admin page with file manager & console
Accessible without login Plain text file colorlog.php Example Example
Plain text file sqlefs.class.php Class SQLEFS Class File

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:6,384
This week:488Up
User Ratings User Comments (2)
 All time
Very interesting initial idea that generates a lot of other i...
8 years ago (Christian Vigh)
thats a amazing class ;-)
8 years ago (Josť Filipe Lopes Santos)