php에서 file reading할때
global $admin_file;
if ($admin_file)
{
$file_params = pathinfo($_FILES['admin_file']['name']);
$file_ext = strtoupper($file_params["extension"]);
if ($file_ext != "XLS" && $file_ext != "CSV" && $file_ext != "TXT")
fatal("잘못된 파일포맷입니다. 지원가능한 파일포맷은 (.xls | .csv | .txt)입니다.");
}
#============================================
#
# data insert
#
switch ($file_ext)
{
case "XLS" :
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP949');
$data->read($admin_file);
$num_rows = $data->sheets[0]['numRows'];
break;
case "CSV" :
$data = file($admin_file);
$num_rows = count($data) + 1;
$fp = fopen($admin_file, "r");
break;
case "TXT" :
$data = file($admin_file);
$num_rows = count($data);
$fp = fopen($admin_file, "r");
break;
}
for ($i = 1; $i <= $num_rows; $i++)
{
switch( $file_ext )
{
case "XLS" :
$x = 0;
$data_array = $data->sheets[0]['cells'][$i];
break;
case "CSV" :
$x = 1;
$data_array = fgetcsv($fp, 1000, ",");
break;
case "TXT" :
$x = 1;
$buffer = fgets($fp, 4096);
$data_array = explode("\t", $buffer);
break;
}
// 작업
$this->save2( $data_array, $x );
flush();
}
댓글 없음:
댓글 쓰기