PHP Classes

PHP File Uploading: Simple library to build your file sharing website

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-03-31 (8 days ago) RSS 2.0 feedNot enough user ratingsTotal: 119 All time: 9,525 This week: 43Up
Version License PHP version Categories
phpfileuploading 1.0.3Custom (specified...7Files and Folders, PHP 7, PSR
Description 

Author

PHP Library to help you build your own file sharing website.

Picture of Faris AL-Otabi
  Performance   Level  
Innovation award
Innovation award
Nominee: 5x

Winner: 1x

 

Recommendations

Example

<?php

session_start
();

include
'../src/Upload.php';
include
'../src/File.php';
include
'../src/Utility.php';

use
Farisc0de\PhpFileUploading\File;
use
Farisc0de\PhpFileUploading\Upload;
use
Farisc0de\PhpFileUploading\Utility;

$upload = new Upload(new Utility());

$upload->setUploadFolder([
   
'folder_name' => 'uploads',
   
'folder_path' => realpath('uploads')
]);

$upload->enableProtection();

if (
$_SERVER['REQUEST_METHOD'] == 'POST') {
   
$file = new File($_FILES['file'], new Utility());

   
$upload->setUpload($file);

    if (
$upload->checkIfNotEmpty()) {
        if (!
$upload->checkForbidden()) {
            echo
"Forbidden name";
            exit;
        }

        if (!
$upload->checkExtension()) {
            echo
"Forbidden Extension";
            exit;
        }

        if (!
$upload->checkMime()) {
            echo
"Forbidden Mime";
            exit;
        }

        if (!
$upload->isImage()) {
            echo
"Not Image";
            exit;
        }

       
$upload->upload();

       
$data = json_decode($upload->getJSON(), true);
    }
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>File Uploading Service</title>
</head>

<body>
    <?php if (isset($data)) : ?>
<p>You file has been uploaded</p>
    <?php endif; ?>

    <form action="" method="post" enctype="multipart/form-data">
        <input type="file" name="file" id="file">
        <button type="submit">Upload</button>
    </form>

    <div>
        <ul>
            <?php if (isset($data)) : ?>
<li>Filename: <?= $data['filename']; ?></li>
                <li>Filehash: <?= $data['filehash']; ?></li>
                <li>Filesize: <?= $data['filesize']; ?></li>
                <li>Upload at: <?= $data['uploaddate']; ?></li>
            <?php endif; ?>
</ul>
    </div>
</body>

</html>


Details

PhpFileUploading

PHP Library to help you build your own file sharing website.

Features

  1. Simple to use and implement
  2. 4 Protection levels 1. Mime Type 2. Extensions 3. Size 4. Forbidden names
  3. Out Of The Box Functions
  4. Multi-File Upload Support

How to install

composer require farisc0de/phpfileuploading

How to Use

take a look at the examples

License

MIT

Copyright

Developed by FarisCode


  Files folder image Files (13)  
File Role Description
Files folder imageexample (3 files)
Files folder imagesrc (5 files)
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:119
This week:0
All time:9,525
This week:43Up