[PHP] Spreadsheet_Excel_Reader 활용해 엑셀 데이터 읽기
<form action="./itemexcelupdate_ing.php" method="post" enctype="multipart/form-data">
<input type="file" name="filepath" id="filepath"/></td><td>
<input type="submit" name="SubmitButton"/>
</form>
위에 처럼 form html 을 만들고
action 이 itemexcelupdate_ing.php로 되어 있으니 아래처럼 만든다.
<?
if(isset($_POST['SubmitButton'])){
$target_dir = 'uploads/';
if( !is_dir($target_dir)){
mkdir($target_dir);
}
print_r( $_FILES["filepath"] );
$target_file = $target_dir. basename($_FILES["filepath"]["name"]);
echo "target_file=".$target_file;
move_uploaded_file($_FILES["filepath"]["tmp_name"], $target_file);
include_once('./Excel/reader.php');
$data = new Spreadsheet_Excel_Reader();
// Set output Encoding.
$data->setOutputEncoding('UTF-8');
$data->read($target_file);
}
?>
엑셀 확장자를 xlsx로 하니 아래처럼 에러 났다.
The filename uploads/test.xlsx is not readable.
인터넷 찾아보니 xlsx를 사용하려면
+ PHPExcel
- http://phpexcel.codeplex.com/
이걸 사용하라고 나와 있었다.