File system php mysql

3 Steps Simple File Sharing In PHP MYSQL (Free Download)

Welcome to a tutorial on how to create a simple file-sharing system in PHP and MYSQL. Have some files on the server that you want to share? But not to everybody? Well, we can create and share a “download link” – Read on for the example!

TABLE OF CONTENTS

PHP MYSQL FILE SHARING

All right, let us now get into the example of a simple PHP MYSQL file-sharing system.

CREATE A PROTECTED FOLDER

This system will be meaningless if the “shared files” can be publicly accessed by anyone. So before we touch on the code, create a “protected shared folder” on your server. There are a few ways to do it:

  • The easy way is to create a shared folder outside of the public HTTP. For example, if the public HTTP folder is at /HTTP/public/ , just create a shared folder at /HTTP/shared/ . Make sure that PHP has read permissions for /HTTP/shared/ though.
  • If you are using Apache, create an .htaccess file in /HTTP/shared/ with just one line – Deny from all .
  • Alternatively, upload and save the files in a database.
Читайте также:  Setup react with typescript

STEP 1) SHARED FILES DATABASE TABLE

CREATE TABLE `file_share` ( `share_hash` varchar(24) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `share_file` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ALTER TABLE `file_share` ADD PRIMARY KEY (`share_hash`);
  • share_hash The primary key and “hash to verify download”. That is, http://site.com/download.php?h=HASH . Take note that this field is case-sensitive.
  • share_file The absolute path of the file on the server. For example, /HTTP/shared/demo.jpg .

STEP 2) FILE SHARE PHP LIBRARY

pdo = new PDO( "mysql:host=".DB_HOST.";dbname=".DB_NAME.";charset=".DB_CHARSET, DB_USER, DB_PASSWORD, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ]); > // (B) DESTRUCTOR - CLOSE DATABASE CONNECTION function __destruct () < if ($this->stmt!==null) < $this->stmt = null; > if ($this->pdo!==null) < $this->pdo = null; > > // (C) EXECUTE SQL QUERY function query ($sql, $data=null) : void < $this->stmt = $this->pdo->prepare($sql); $this->stmt->execute($data); > // (D) GET SHARED FILE BY HASH function getHash ($hash) < $this->query("SELECT * FROM `file_share` WHERE `share_hash`=?", [$hash]); return $this->stmt->fetch(); > // (E) GET SHARED FILE BY FILE NAME function getFile ($file) < $this->query("SELECT * FROM `file_share` WHERE `share_file`=?", [$file]); return $this->stmt->fetch(); > // (F) SHARE A FILE function share ($file) < // (F1) CHECK FILE if (!file_exists($file)) < $this->error = "$file does not exist"; return false; > $check = $this->getFile($file); if (is_array($check)) < return DL_URL . $check["share_hash"]; >// (F2) CREATE/CHECK HASH // CREDITS : https://stackoverflow.com/questions/4356289/php-random-string-generator $length = 16; $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $len = strlen($chars); while ($hash===null) < $random = ""; for ($i=0; $iif (!is_array($this->get($random))) < $hash = $random; >> // (F3) INSERT ENTRY $this->query("INSERT INTO `file_share` (`share_hash`, `share_file`) VALUES (. )", [$hash, $file]); return DL_URL . $hash; > // (G) READ FILE & FORCE DOWNLOAD function download ($hash) < // (G1) GET HASH & CHECK if (!isset($_GET["h"])) < exit("Invalid download"); >$file = $this->getHash($_GET["h"]); if (!is_array($file)) < exit("Invalid download"); >if (!file_exists($file["share_file"])) < exit("Invalid download"); >// (G2) FORCE DOWNLOAD header("Content-Type: application/octet-stream"); header("Content-Type: Content-Transfer-Encoding: Binary"); header("Content-disposition: attachment; filename=\"".basename($file["share_file"])."\""); readfile($file["share_file"]); > > // (H) DATABASE SETTINGS - CHANGE TO YOUR OWN define("DL_URL", "http://localhost/3b-download.php?h="); define("DB_HOST", "localhost"); define("DB_NAME", "test"); define("DB_CHARSET", "utf8mb4"); define("DB_USER", "root"); define("DB_PASSWORD", ""); // (I) NEW FILE SHARE OBJECT $_FS = new FileShare();
  • (A, B, I) When $_FS = new FileShare() is created, the constructor connects to the database. The destructor closes the connection.
  • (C) query() A support function to run an SQL query.
  • (D to G) There are only “4 actual system functions”.
    • getHash() Get a shared file by hash.
    • getFile() Get a shared file by file name.
    • share() Step 1 of the process, pass in the file to share and this returns the download link.
    • download() “Step 2” of the process, check a given hash and force download.
    share(__DIR__ . "/0-PHP-FILE-SHARE.MD"); echo $link===false ? $_FS->error : $link;

    Don’t think this needs a lot of explanation. Just call $_FS->share(FILE-TO-SHARE) and share the download link – For this demo, we will share the README file.

    3B) VERIFY & DOWNLOAD

    Lastly, the user accesses http://site.com/3b-download.php?h=HASH . This will verify the hash and force a download.

    DOWNLOAD & NOTES

    Firstly, here is the download link to the example code as promised.

    SUPPORT

    600+ free tutorials & projects on Code Boxx and still growing. I insist on not turning Code Boxx into a «paid scripts and courses» business, so every little bit of support helps.

    EXAMPLE CODE DOWNLOAD

    Click here for the source code on GitHub gist, just click on “download zip” or do a git clone. I have released it under the MIT license, so feel free to build on top of it or use it in your own project.

    That’s all for the tutorial, and here is a small section on some extras and links that may be useful to you.

    SKELETAL SYSTEM ONLY!

    • Add a “download history” table for added security. Keep track of the download file, time, and IP address.
    • We can technically have a bazillion download hash codes, but it will be nice to have some sort of clean-up mechanism. Follow up with the previous “download history” – If a file has not been downloaded for a year, delete the hash code and file (or at least notify the administrators).
    • More “download controls” – Set an expiry date and number of download times.
    • If you want more security, keep the downloads to registered users only – In download() of 2-lib-share.php , do a if (!isset($_SESSION[«user»])) < exit("NOT SIGNED IN"); >.
    • Captain Obvious, there are no file uploads nor file managers in this tutorial. There are plenty of free ones, follow up with the links below.

    THE END

    Thank you for reading, and we have come to the end. I hope that it has helped you to better understand, and if you want to share anything with this guide, please feel free to comment below. Good luck and happy coding!

    Leave a Comment Cancel Reply

    Breakthrough Javascript

    Take pictures with the webcam, voice commands, video calls, GPS, NFC. Yes, all possible with Javascript — Check out Breakthrough Javascript!

    Socials

    About Me

    W.S. Toh is a senior web developer and SEO practitioner with over 20 years of experience. Graduated from the University of London. When not secretly being an evil tech ninja, he enjoys photography and working on DIY projects.

    Code Boxx participates in the eBay Partner Network, an affiliate program designed for sites to earn commission fees by linking to ebay.com. We also participate in affiliate programs with Bluehost, ShareASale, Clickbank, and other sites. We are compensated for referring traffic.

    Источник

    File Management System Project In PHP With Source Code

    File Management System in PHP with Source Code

    A File Management System Project In PHP helps you to store, exchange, and maintain all of your company’s file records. This project’s functionality can be applied to colleges, offices, or any other organization that wants to handle and store their file records.

    The file management system in php and mysql users will be able to manage their documents online as part of this initiative. The features of the project are possibly inspired by Google Drive File Management, with the exception that this framework would only concentrate on a single entity or institution.

    In this online file management system php allows users to save their documents as well as the file’s overview. Users can also organize their files by creating folders to group similar files together. Only the administrator can build a user in this framework to protect documents that are marked as shared with all.

    About The Project

    The File Management System In PHP With Source Code is developed using HMTL, CSS, PHP, Bootstrap and MySQL database, this file management system in php was used to monitor, maintain, and store files in order to minimize the number of hard copies on hand.

    Project Information’s

    These are the following features of the system

    • Admin
      • Username: admin
      • Password: admin
      • Username: user
      • Password: user

      Steps On How To Run The File Management System Project In PHP With Source Code

      First, download the source code given below.

      Step 2: Extract file.

      Second, after you finished download the source code, extract the zip file.

      Step 3: Copy project folder.

      Third, copy the project folder and paste it into the xampp/htdocs folder.

      Fourth, open xampp and start the apache and MySQL.

      Step 5: Open browser.

      Fifth, Open a browser and go to URL “http://localhost/phpmyadmin/

      Step 6: Create database.

      Sixth, click on databases tab and Create database naming “fms_db”.

      Seventh, Click on browse file and select “fms_db.sql” file which is inside “database” folder and after import click “go“.

      Step 8: Open browser and type folder name.

      Eight, Open a browser and go to URL “http://localhost/file/”.

    Downloadable Source Code

    Conclusion

    This file management system in php is only a project made for school requirement purposes only. You can download this source code and modify it to suit your client requirements, since this is a student project it means you cannot really expect 100% functionality from this.

    Inquiries

    If you have any questions or suggestions about file management system project in php with source code, please feel free to leave a comment below.

    Источник

    Project: Complete File Management System using PHP and MySQL with Source Code

    file management system project

    About Complete File Management System using PHP MySQL Project Free Download

    File Management System in PHP MySQL is a system that is based on computer programs in the case of the management of digital documents which used to track, manage, and store documents and reduce stock hard copies. Most are capable of keeping a record of the various versions created and modified by different users such as history tracking.

    Features of Complete File Management System Project

    —-Admin——
    – secure login
    -With Dashboard Count Employee Upload file
    -Add Admin with View/Edit/Delete
    -Add Employee with View/Edit/Delete
    -Add Document
    -Extension file: .docx .doc .pptx .ppt .xlsx .xls .pdf .odt
    -Count every Download
    -Download /View File/Delete file
    -Show Admin Logged
    -Show Employee Logged
    -Show table records
    – Login/Logout

    -with the archive file
    -delete/download only
    -create own folder for path /save own file
    -Auto logout after 20 minutes

    —Employee—
    secure login
    -Add file
    -Show table record
    -Show Employee Logged
    -Download file
    -Login/logout

    Screenshots

    complete file management system

    complete file management system

    file management system php project

    How To Run??

    Above all, to run this project you must have installed a virtual server i.e XAMPP on your PC. Complete File Management System Project in PHP and MySQL with source code is free to download, Use for educational purposes only!

    Follow the following steps after Starting Apache and MySQL in XAMPP:

    1st Step: Firstly, Extract the file
    2nd Step: After that, Copy the main project folder
    3rd Step: So, you need to Paste in xampp/htdocs/

    Further, Now Connecting Database

    4th Step: So, for now, Open a browser and go to URL “http://localhost/phpmyadmin/”
    5th Step: After that, Click on the databases tab
    6th Step: So, Create a database naming “file_management” and then click on the import tab
    7th Step: Certainly, Click on browse file and select “file_management.sql” file which is inside the “db” folder
    8th Step: Meanwhile, click on Go button.

    After Creating Database,

    9th Step: Moreover, Open a browser and go to URL “http://localhost/filemanagement”

    ADMIN URL: http://localhost/filemanagement/Private_Dashboard/
    email:
    admin@campcodes.com
    password:
    admin123

    DEMO

    Источник

Оцените статью