Skip to content

Instantly share code, notes, and snippets.

@plasticbrain
Created September 11, 2012 23:02
Show Gist options
  • Save plasticbrain/3702841 to your computer and use it in GitHub Desktop.
Save plasticbrain/3702841 to your computer and use it in GitHub Desktop.
PHP: Upload and parse CSV file
<form action="" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="btn_submit" value="Upload File" />
<?php
$fh = fopen($_FILES['file']['tmp_name'], 'r+');
$lines = array();
while( ($row = fgetcsv($fh, 8192)) !== FALSE ) {
$lines[] = $row;
}
var_dump($lines);
?>
@imadeous
Copy link

Is there any way to insert the resulting array into sql table?

@mikenk2010
Copy link

using blob data type in mysql.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment