Solusinya adalah dengan menulis file ke memory!
Snippet :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$allocated_csv = $output_dir.DIRECTORY_SEPARATOR."allocated-raw.csv" ; | |
if (($handle = fopen($allocated_csv, "r")) !== FALSE) { | |
//maksimal 1024*(1024*100) = 100MB | |
$handle_memory = fopen('php://temp/maxmemory:104857600', 'w'); | |
$allocated_data = array(); | |
while (($data = fgetcsv($handle)) !== FALSE) { | |
$allocated_data = array($nomor_peserta_arr[$data[0]], $data[0], $data[1], $data[2]) ; | |
fputcsv($handle_memory, $allocated_data); | |
} | |
fclose($handle); | |
rewind($handle_memory); | |
$allocated_csv_memory = stream_get_contents($handle_memory); | |
fclose($handle_memory); | |
$allocated_csv_tmp = '/tmp/allocated-raw.csv'; | |
$handle = fopen($allocated_csv_tmp, 'w'); | |
fwrite($handle, $allocated_csv_memory); | |
fclose($handle); | |
$sql = "LOAD DATA INFILE '{$allocated_csv_tmp}' REPLACE INTO TABLE allocated FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n'"; | |
$conn = Doctrine_Manager::getInstance()->getCurrentConnection(); | |
$conn->execute($sql); | |
} |
- Create CSV file in memory PHP, http://www.metashock.de/2014/02/create-csv-file-in-memory-php/
No comments:
Post a Comment