...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?php try { //업로드 upload 디렉토리path $uploadDir = 'uploads/docs'; //폼 form 데이터filed 이름name $fieldName = 'file'; //파일 file 이름name $fileName = explode('.', $_FILES[$fieldName]['name']); //파일file 확장자extension $extension = end($fileName); //임시 temp 파일file 이름name $tmpName = $_FILES[$fieldName]['tmp_name']; //저장될 새로운 파일이름 new file name to save $newFileName = sha1(microtime()); //실제 파일file 업로드upload 경로path $fileUploadPath = "${uploadDir}/${newFileName}.${extension}"; //파일을 저장합니다 save file to disk move_uploaded_file($tmpName, $fileUploadPath); //문서 변환을 결과를 저장하는 디렉토리 directory name to save conversion result $wordDir = 'works'; //문서 execute 변환conversion $zipFilePath$importPath = "${wordDir}/${newFileName}.zip"; executeConverter($fileUploadPath, $zipFilePath$importPath); //압축 풀기serialize document data $unzipFilePath = "${wordDir}/${newFileName}"; unzip($zipFilePath, $unzipFilePath); //데이터 직렬화 $pbFilePath = "${unzipFilePathimportPath}/document.word.pb"; $serializedData = readPBData($pbFilePath); // 클라이언트로 응답을 보냅니다.send response header('Content-Type: application/json'); echo json_encode(array( 'serializedData' => $serializedData, 'importPath' => $unzipFilePath$importPath, )); } catch (Exception $e) { echo $e->getMessage(); http_response_code(404); } function executeConverter($inputFilePath, $outputFilePath) { $sedocConverterPath = 'c:/sedocConverter/sedocConverter.exe'; $fontsDir = 'c:/sedocConverter/fonts'; $tempDir = 'c:/sedocConverter/tmp'; $cmd = "${sedocConverterPath} -f ${fontsDir} ${inputFilePath} ${outputFilePath} ${tempDir}"; exec($cmd); } function unzip($zipFilePath, $unzipFilePath) { $zip = new ZipArchive; if ($zip->open($zipFilePath) === true) { $zip->extractTo($unzipFilePath); $zip->close(); } } function readPBData($pbFilePath) { $fb = fopen($pbFilePath, 'r'); $data = stream_get_contents($fb, -1, 16); fclose($fb); $byteArray = unpack('C*', zlib_decode($data)); $serializedData = array_values($byteArray); return $serializedData; } |
...