開発メモ

開発用のメモです。

Cakephp CSVファイル読み込み

$toFile = $this->request->data["toFile"];

$tos = array();
$size = $toFile["size"];
$tname = $toFile["tmp_name"];

$fh = fopen($tname, "r");
// 文字コードを UTF8へ変換
$_body = mb_convert_encoding(fread($fh, $size), 'utf8', 'auto'); 
fclose($fh);

$fh = fopen($tname, "w");
fwrite($fh, $_body);
fclose($fh);

$fh = fopen($tname, "r");
while (($csv = fgetcsv($fh)) != false) {
    array_push($tos, $csv[0]);
}
Twitter: @asahina_alice