Skip to main content

PHP - Upload Files To SQLite Using PDO


In this tutorial we will create a Upload Files To SQLite Using PDO. This code can be use for storing of list of data. PHP is a server-side scripting language designed primarily for web development. SQLite provides an interface for accessing the database. It includes class interfaces to the SQL commands. And also it allows you to create SQL functions and aggregate using PHP. So Let's do the coding...

Getting started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html. And this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/. Installing SQLite Browser We will now then install the SQLite data viewer, here's the link for the DB Browser for SQLite http://sqlitebrowser.org/.

Setting Up SQLite

First, we are going to enable SQLite 3 in our PHP. 1. Open localhost server folder XAMPP, etc and locate php.ini. 2. Open php.ini and enable sqlite3 by removing the semicolon in the line. tut1 3. Save changes and Restart Server.

Creating the database connection

Open your any kind of text editor(notepad++, etc..). Then just copy/paste the code below then name it conn.php. setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $query = "CREATE TABLE IF NOT EXISTS file (file_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, file_name TEXT, file_type TEXT, file_size TEXT, location TEXT)"; $conn->exec($query); ?>

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into you text editor, then save it as index.php.

PHP - Upload Files To SQLite Using PDO




prepare("SELECT * FROM `file` ORDER BY `file_type` ASC"); $query->execute(); while($fetch = $query->fetch()){ ?>
File Name File Type File Size Location

Creating the Main Function

This code contains the main function of the application. This code will upload files into the SQLite database. To do this just copy and write these block of codes as shown below inside the text editor and save it as save_file.php. prepare($query); $stmt->bindParam(':file_name', $name); $stmt->bindParam(':file_type', $file_type); $stmt->bindParam(':file_size', $file_size); $stmt->bindParam(':location', $path); $stmt->execute(); $conn = null; echo ""; echo ""; } } ?> There you have it we successfully created a Upload Files To SQLite Using PDO. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.