Date: Fri, 29 Mar 2024 10:45:23 +0900 (KST) Message-ID: <551598111.7121.1711676723326@localhost> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_7120_2002812821.1711676723325" ------=_Part_7120_2002812821.1711676723325 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Caution
Among the following codes provided as the guide, file upload part is a <= strong>sample code and has insufficient security.
As for the file upload, please use the code used within your project and= refer the following code to handle the system link.
<?php try { //Upload directory $uploadDir =3D 'uploads/images'; //Name of the form data $fieldName =3D 'file'; //File name $fileName =3D explode('.', $_FILES[$fieldName]['name']); //Filename extension $extension =3D end($fileName); //Temporary file name $tmpName =3D $_FILES[$fieldName]['tmp_name']; //File name for the new save $newFileName =3D sha1(microtime()); //Actual file upload path $fileUploadPath =3D "${uploadDir}/${newFileName}.${extension}"; //Save the file move_uploaded_file($tmpName, $fileUploadPath); //Send the response to the client. header('Content-Type: application/json'); echo json_encode(array( 'uploadPath' =3D> $fileUploadPath, )); } catch (Exception $e) { echo $e->getMessage(); http_response_code(404); }=20
Caution
Among the following codes provided as the guide, file upload part is a <= strong>sample code and has insufficient security.
As for the file upload, please use the code used within your project and= refer the following code to handle the system link.
<?php try { // Upload directory $uploadDir =3D 'uploads/docs'; // Name of the form data $fieldName =3D 'file'; // File name $fileName =3D explode('.', $_FILES[$fieldName]['name']); //Filename extension $extension =3D end($fileName); // Temporary file name $tmpName =3D $_FILES[$fieldName]['tmp_name']; // File name for the new save $newFileName =3D sha1(microtime()); // Actual file upload path $fileUploadPath =3D "${uploadDir}/${newFileName}.${extension}"; // Save the file move_uploaded_file($tmpName, $fileUploadPath); // Directory name to save conversion result $wordDir =3D 'works'; // Execute conversion $importPath =3D "${wordDir}/${newFileName}"; executeConverter($fileUploadPath, $importPath); // Serialize document data =09// Since v2.3.0, the file name is changed from document.word.pb to docum= ent.pb $pbFilePath =3D "${importPath}/document.pb"; $serializedData =3D readPBData($pbFilePath); // Send the response to the client. header('Content-Type: application/json'); echo json_encode(array( 'serializedData' =3D> $serializedData, 'importPath' =3D> $importPath, )); } catch (Exception $e) { echo $e->getMessage(); http_response_code(404); } function executeConverter($inputFilePath, $outputFilePath) { $sedocConverterPath =3D 'c:/sedocConverter/sedocConverter.exe'; $fontsDir =3D 'c:/sedocConverter/fonts'; $tempDir =3D 'c:/sedocConverter/tmp'; $cmd =3D "${sedocConverterPath} -f ${fontsDir} ${inputFilePath} ${outpu= tFilePath} ${tempDir}"; exec($cmd); } function readPBData($pbFilePath) { $fb =3D fopen($pbFilePath, 'r'); $data =3D stream_get_contents($fb, -1, 16); fclose($fb); $byteArray =3D unpack('C*', zlib_decode($data)); =09// php 5.4.0 or below // $byteArray =3D unpack('C*', gzuncompress($data)); $serializedData =3D array_values($byteArray); return $serializedData; }=20