Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. <?php
  2. include 'datawarputil.php';
  3. include 'getmimetype.php';
  4.  
  5. ini_set('memory_limit', '4000M');
  6. ini_set('max_execution_time', 2000);
  7.  
  8. /*if (!$_FILES || count($_FILES) == 0) {
  9. echo "No files attached";
  10. exit;
  11. }*/
  12.  
  13. //$upload = array_shift($_FILES);
  14. //$filename = $upload['name'];
  15. //$fileUrl = $upload['tmp_name'];
  16. $filename = $_REQUEST['name'];
  17. $chunksIDs = $_REQUEST['chunksIDs'];
  18. $firstFileUrl = "";
  19. $fileUrl = "";
  20. $sql = "SELECT chunk_content FROM file_chunks WHERE id IN " . $chunksIDs . " ORDER BY chunk_id";
  21. $result = array();
  22. $result[] = exec_query("", $sql, array());
  23. foreach (current($result) as $res) {
  24. $fileUrl = $fileUrl . $res[0];
  25. if ($firstFileUrl == "") {
  26. $firstFileUrl = $res[0];
  27. }
  28. }
  29.  
  30. $sql = "DELETE FROM file_chunks WHERE id IN " . $chunksIDs;
  31. $result = array();
  32. $result[] = exec_query("", $sql, array());
  33.  
  34. $info = new SplFileInfo($filename);
  35. $fileNameEndIndex = strrpos($filename, ".");
  36. $extension = substr($filename, $fileNameEndIndex + 1);
  37. $output = array();
  38.  
  39. $mimeType = getMimeType($extension);
  40. $content = $fileUrl;
  41. $size = null;
  42. if ($mimeType == "image/jpeg")
  43. $size = getimagesize($firstFileUrl);
  44.  
  45. $sql = "INSERT INTO files_content(`data`) VALUES (:a0)";
  46. $result = array();
  47. $result[] = exec_query("", $sql, array('a0' => $content));
  48.  
  49. $sql = "SELECT LAST_INSERT_ID() AS id";
  50. $insertId = exec_query("", $sql, array())[0][0];
  51.  
  52. $sql = "INSERT INTO files_metadata(`content_id`, `ext`, `width`, `height`, `parent_id`, `size`) VALUES (:a0, :a1, :a2, :a3, :a4, :a5)";
  53. $result = array();
  54. $result[] = exec_query("", $sql, array('a0' => $insertId, 'a1' => $mimeType, 'a2' => $size[0], 'a3' => $size[1], 'a4' => null, 'a5' => strlen($content)));
  55.  
  56. $output[] = $insertId;
  57.  
  58. if ($mimeType == "application/pdf") {
  59. $tempDir = sys_get_temp_dir();
  60. $tempDirUpdated = $tempDir;
  61. if ($tempDir[0] == "/" && $tempDir[strlen($tempDir) - 1] != "/") { // Unix
  62. $tempDirUpdated = $tempDirUpdated . "/";
  63. } elseif ($tempDir[0] != "/" && $tempDir[strlen($tempDir) - 1] != "\\") { // Windows
  64. $tempDirUpdated = $tempDirUpdated . "\\";
  65. }
  66. $tempPdfUrl = $tempDirUpdated . "1.pdf";
  67. file_put_contents($tempPdfUrl, $content);
  68. exec("pdf2svg " . "\"" . $tempPdfUrl . "\" \"" . $tempDirUpdated . "%d.svg\" all");
  69. unlink($tempPdfUrl);
  70. $i = 1;
  71. for (; ; ) {
  72. $curFileUrl = $tempDirUpdated . "{$i}.svg";
  73. if (file_exists($curFileUrl)) {
  74.  
  75. $content = file_get_contents($curFileUrl);
  76.  
  77. $sql = "INSERT INTO files_content(`data`) VALUES (:a0)";
  78. $result = array();
  79. $result[] = exec_query("", $sql, array('a0' => $content));
  80.  
  81. $sql = "SELECT LAST_INSERT_ID() AS id";
  82. $curInsertId = exec_query("", $sql, array())[0][0];
  83.  
  84. $sql = "INSERT INTO files_metadata(`content_id`, `ext`, `width`, `height`, `parent_id`, `size`) VALUES (:a0, :a1, :a2, :a3, :a4, :a5)";
  85. $result = array();
  86. $result[] = exec_query("", $sql, array('a0' => $curInsertId, 'a1' => getMimeType("svg"), 'a2' => null, 'a3' => null, 'a4' => $insertId, 'a5' => strlen($content)));
  87. $output[] = $curInsertId;
  88.  
  89. unlink($curFileUrl);
  90. } else {
  91. break;
  92. }
  93. $i = $i + 1;
  94. }
  95. }
  96.  
  97. echo json_encode($output);
  98. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement