Giter Site home page Giter Site logo

file-upload-using-php's Introduction

File-upload-using-PHP

upload a CSV file using PHP file upload functionality and insert the data into a DB

For simplicity, I have everything including the PHP code, Bootstrap and DB connection all in one file: csv_upload.php

Bootstrap- submit type input field to upload the file

<p> Upload CSV: <input type="file" name="file"></p>
<p> <input type="submit" name="submitfile" value="Import"></p>

PHP- 1. check if file extension is csv

if($_FILES['file']['name'])
	{
		$filename = explode(".", $_FILES['file']['name']);
		if($filename[1]=='csv')
  1. check if the size is under 1MB (or anything else user can specify)
if ($_FILES['file']['size'] < 1000000)  //filesize is always in kb
  1. insert csv file data into the DB table called csv_data
$sql = "insert into csv_data(id, name, email, phone, street_address, city, state, postal_code) values('','$item1'
,'$item2','$item3','$item4','$item5','$item6','$item7')";
mysqli_query($db, $sql) or die(mysqli_error($db)."...at line- ". __LINE__);
  1. close Mysql connection
mysqli_close($db);

file-upload-using-php's People

Contributors

manishkak avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.