Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <body>
- <?php
- $con = mysqli_connect("localhost","root","","DBName");
- if ($_FILES['csv']['size'] > 0) {
- //get the csv file
- $file = $_FILES['csv']['name'];
- $handle = fopen($file,"r");
- $file_type = pathinfo($file,PATHINFO_EXTENSION);
- //loop through the csv file and insert into database
- while ($data = fgetcsv($handle,1000,",")) {
- if ($data[0]) {
- mysqli_query($con, "INSERT INTO users (username, first_name, last_name) VALUES
- (
- '".addslashes ($data[0])."',
- '".addslashes ($data[1])."',
- '".addslashes ($data[2])."'
- )
- ");
- }
- }
- exit;
- }
- ?>
- <form action="" method="post" enctype="multipart/form-data">
- <input type="file" name="file" /><br />
- <input type="submit" name="submit" value="Submit" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement