Thursday, July 24, 2014

Import a Large CSV file to MySQL commend line

Using the mysqlimport utility run below command.


mysqlimport  --ignore-lines=1 --fields-terminated-by=,--columns='ID,
columnName1,columnname2, columnname3' --local -u root -p 
Databasename /pathtocsvfile/tablename.csv


You must put the absolute path of the csv file for it to register with 
the utility. The “tablename.csv” has to match the name of the table in 
your mysql database.

For more information on the mysqlimport utility: Click Here

Wednesday, May 28, 2014

Validation uploaded File in php


if(isset($_FILES['uploaded_file'])) {
    $errors     = array();
    $maxsize    = 1000000;
    $acceptable = array(
        'image/jpg',
        'image/gif',
        'image/png',
        'application/pdf',
        'image/jpeg',
        
    );

    if(($_FILES['uploaded_file']['size'] >= $maxsize) || ($_FILES["uploaded_file"]["size"] == 0)) {
        $errors[] = 'File too large. File must be less than 1MB.';
    }

    if(!in_array($_FILES['uploaded_file']['type'], $acceptable)) && (!empty($_FILES["uploaded_file"]["type"])))
    {
    $errors[] = 'Invalid file type. Only PDF, JPG, GIF and PNG types are accepted.';
    }

if(count($errors) === 0) {
    move_uploaded_file($_FILES['uploaded_file']['tmpname'], '/store/to/location.file');
} else {
    foreach($errors as $error) {
        echo '<script>alert("'.$error.'");</script>';
    }

    die(); //Ensure no more processing is done
}
}