PHP Classes

File: sample.php

Recommend this page to a friend!
  Classes of Md. Kausar Alam   File Importer   sample.php   Download  
File: sample.php
Role: Example script
Content type: text/plain
Description: example file of fileImporter class
Class: File Importer
Import data from CSV files into a MySQL database
Author: By
Last change:
Date: 15 years ago
Size: 1,048 bytes
 

Contents

Class file image Download
<?php
include('fileImporter.class.php');
?>
<form name="frmImportFile" enctype="multipart/form-data" method="post">
<input type="hidden" name="value" value="yes">
<table width="80%" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td>Import File</td>
        <td><input type="file" name="import_file" id="import_file" /><input type="submit" value="submit" /></td>
    </tr>
</table>
</form>
<?php
if ( $_POST['value'] == 'yes' ) {
   
//set the temp dir
   
echo $path = $_SERVER['DOCUMENT_ROOT'].'fileUploaded/temp/';
   
//create an object of this class
   
$importer = new fileImporter( $path , 'zend' , 'user' );
   
//create DB connection, if DB is not connected
   
$importer->connectDatabase( 'localhost', 'root' ,'');
   
//set delimiter,by defult tab
   
$importer->setDelimiter('comma'); //FOR COMMA,use $importer->setDelimiter('comma');
    //import file
   
if( $importer->importFile() ) {
       echo
'File imported successfully';
    } else {
        echo
"Error Occured!Please try again";
    }
}