1. Installing JSON Encoder
Download : JSON.phps
2. Uploading Image (Same for Uploading Videos and Files)
Caution
Among the following codes provided as the guide, file upload part is a 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 //Upload directory $uploadDir = 'uploads/images'; //Name of the form data $fieldName = 'file'; //File name $fileName = explode('.', $_FILES[$fieldName]['name']); //Filename extension $extension = end($fileName); //Temporary file name $tmpName = $_FILES[$fieldName]['tmp_name']; //File name for the new save $newFileName = sha1(microtime()); //Actual file upload path $fileUploadPath = "${uploadDir}/${newFileName}.${extension}"; //Save the file move_uploaded_file($tmpName, $fileUploadPath); // Include JSON Encoder. include("./JSON.phps"); //Send the response to the client. header('Content-Type: application/json'); echo json_encode_new(array( 'uploadPath' => $fileUploadPath, )); function json_encode_new($data) { $json = new Services_JSON(); return($json->encode($data)); } ?>
3. Importing HWP, MS Word and Excel Documents
Caution
Among the following codes provided as the guide, file upload part is a 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 // Upload directory $uploadDir = 'uploads/docs'; // Name of the form data $fieldName = 'file'; // File name $fileName = explode('.', $_FILES[$fieldName]['name']); //Filename extension $extension = end($fileName); // Temporary file name $tmpName = $_FILES[$fieldName]['tmp_name']; // File name for the new save $newFileName = sha1(microtime()); // Actual file upload path $fileUploadPath = "${uploadDir}/${newFileName}.${extension}"; // Save the file move_uploaded_file($tmpName, $fileUploadPath); // Directory name to save conversion result $wordDir = 'works'; // Execute conversion $importPath = "${wordDir}/${newFileName}"; executeConverter($fileUploadPath, $importPath); // Serialize document data // Since v2.3.0, the file name is changed from document.word.pb to document.pb $pbFilePath = "${importPath}/document.pb"; $serializedData = readPBData($pbFilePath); include("./JSON.phps"); // Send the response to the client. header('Content-Type: application/json'); echo json_encode_new(array( 'serializedData' => $serializedData, 'importPath' => $importPath, )); 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 readPBData($pbFilePath) { $filesize = filesize($pbFilePath); $zd = gzopen($pbFilePath, "r"); $data = substr( gzread($zd, $filesize), 16 ); gzclose($zd); $byteArray = unpack('C*', gzuncompress($data)); $serializedData = array_values($byteArray); return $serializedData; } function json_encode_new($data) { $json = new Service_JSON(); return($json->encode($data)); } ?>