Esempio n. 1
0
function uploadFiletoDB($UserFileName)
{
    $TransactionArray = array();
    $TblName = TableName;
    $FileName = $_FILES[$UserFileName]['name'];
    $FileServerName = $_FILES[$UserFileName]['tmp_name'];
    $CSVFIle = 'transactionTable.csv';
    $CSVDelimiter = ';';
    $ValidRecordswrited = 0;
    $InvalidRecords = 0;
    if (getFileExtension($FileName) == 'xlsx') {
        convertXLStoCSV($FileServerName, $CSVFIle);
        $CSVDelimiter = ',';
    } else {
        $CSVFIle = $FileServerName;
    }
    $TransactionArray = csv_to_array($CSVFIle, $CSVDelimiter);
    if (sizeof($TransactionArray) > 100000) {
        echo '<br>';
        echo "Error - file rows cont is to much";
        return false;
    }
    $Connection = mysql_connect(ServerName, UserName, Password);
    $db_selected = mysql_select_db(DBName, $Connection);
    if (!$Connection) {
        die("Connection failed: " . mysql_error());
    }
    foreach ($TransactionArray as $Line) {
        if (checkTransactionRecord($Line)) {
            $Request = "INSERT INTO {$TblName}(`Account`, `Description`, `CurrencyCode`, `Ammount`) VALUES ('{$Line['Account']}','{$Line['Description']}','{$Line['CurrencyCode']}',{$Line['Amount']})";
            $result = mysql_query($Request);
            if (!$result) {
                echo 'Query error: ' . mysql_error();
            } else {
                $ValidRecordswrited++;
            }
        } else {
            $InvalidRecords++;
        }
    }
    mysql_close($Connection);
    echo '<br> <br>';
    echo "Valid records writed to DataBase: {$ValidRecordswrited}";
    echo '<br>';
    echo "Invalid records count: {$InvalidRecords}";
}
Esempio n. 2
0
<?php

if ($_FILES["file"]["error"] > 0) {
    echo "Error: " . $_FILES["file"]["error"] . "<br>";
} else {
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . $_FILES["file"]["size"] / 1024 . " kB<br>";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
    move_uploaded_file($_FILES["file"]["tmp_name"], "C:/xampp/htdocs/ita_project/ " . $_FILES["file"]["name"]);
    echo "Stored in: " . "ita_project/" . $_FILES["file"]["name"];
    $inputfile = $_FILES["file"]["name"];
    //echo "\n" . $inputfile;
}
require_once 'PHPExcel/Classes/PHPExcel.php';
//include 'upload_file.php';
//Usage:
convertXLStoCSV($inputfile, 'output.csv');
function convertXLStoCSV($infile, $outfile)
{
    $fileType = PHPExcel_IOFactory::identify($infile);
    $objReader = PHPExcel_IOFactory::createReader($fileType);
    $objReader->setReadDataOnly(true);
    $objPHPExcel = $objReader->load($infile);
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
    $objWriter->save($outfile);
    echo "<h2>Successful<h2>";
}
?>
 
Esempio n. 3
0
<?php

function download_remote_file($file_url, $save_to)
{
    $content = file_get_contents($file_url);
    file_put_contents($save_to, $content);
}
download_remote_file('http://www.boi.org.il//he/DataAndStatistics/Lists/BoiTablesAndGraphs/itrchovh.xls', realpath("./xls_data") . '/overdraft.xls');
require_once 'PHPExcel/Classes/PHPExcel.php';
//Usage:
convertXLStoCSV('xls_data/overdraft.xls', '../data/overdraft.csv');
function convertXLStoCSV($infile, $outfile)
{
    $fileType = PHPExcel_IOFactory::identify($infile);
    $objReader = PHPExcel_IOFactory::createReader($fileType);
    $objReader->setReadDataOnly(true);
    $objPHPExcel = $objReader->load($infile);
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
    $objWriter->save($outfile);
}
Esempio n. 4
0
<?php

// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "http://www.aaii.com/files/surveys/sentiment.xls");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$xlsData = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
require_once 'Classes/PHPExcel.php';
$file = fopen("sentiment.xls", "w");
fwrite($file, $xlsData);
fclose($file);
convertXLStoCSV("sentiment.xls", 'output.csv');
function convertXLStoCSV($infile, $outfile)
{
    $fileType = PHPExcel_IOFactory::identify($infile);
    $objReader = PHPExcel_IOFactory::createReader($fileType);
    $objReader->setReadDataOnly(true);
    $objPHPExcel = $objReader->load($infile);
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
    $objWriter->save($outfile);
}
?>