You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. session_start();
  3. #error_log("Here is upload.php");
  4. file_put_contents("/tmp/log.txt", "uploadder\n", FILE_APPEND | LOCK_EX);
  5. function xvar_dump ($x) {
  6. ob_start();
  7. var_dump($x);
  8. return ob_get_clean();
  9. }
  10. $jo = array();
  11. foreach ($_FILES as $key=>$files){
  12. for ($i=0; $i < count($files['name']); $i++){
  13. $tmpname = $files['tmp_name'][$i];
  14. $ft = mime_content_type($tmpname);
  15. file_put_contents("/tmp/log.txt", "MIME: $ft\n", FILE_APPEND | LOCK_EX);
  16. if ($ft == "application/pdf"){
  17. $jo ["file-$key-$i"] = array(
  18. "url" => "url.txt",
  19. "name" => $files['name'][$i],
  20. "id" => $tmpname,
  21. "size" => sprintf("%0.1fK",$files['size'][$i]/1024.0)
  22. );
  23. file_put_contents("/tmp/log.txt", "file-$key-$i\n", FILE_APPEND | LOCK_EX);
  24. file_put_contents("/tmp/log.txt", $files['name'][$i], FILE_APPEND | LOCK_EX);
  25. $_SESSION['files'][$tmpname]['content']=file_get_contents($tmpname);
  26. $_SESSION['files'][$tmpname]['row']=$_GET['row'];
  27. }else if ($ft == "image/jpeg") {
  28. $jo ["file-$key-$i"] = array(
  29. "url" => "url.txt",
  30. "name" => $files['name'][$i],
  31. "id" => $tmpname,
  32. "size" => sprintf("%0.1fK",$files['size'][$i]/1024.0)
  33. );
  34. file_put_contents("/tmp/log.txt", "file-$key-$i\n", FILE_APPEND | LOCK_EX);
  35. file_put_contents("/tmp/log.txt", $files['name'][$i], FILE_APPEND | LOCK_EX);
  36. $tmpfname = tempnam("/tmp", "FOO");
  37. $cmd = "/usr/local/bin/convert $tmpname PDF:$tmpfname";
  38. exec ($cmd);
  39. file_put_contents("/tmp/log.txt", "\n$cmd\n");
  40. $_SESSION['files'][$tmpname]['content']=file_get_contents($tmpfname);
  41. $_SESSION['files'][$tmpname]['row']=$_GET['row'];
  42. unlink ($tmpfname);
  43. }
  44. else {
  45. file_put_contents("/tmp/log.txt", "ERRORZWEIK\n", FILE_APPEND | LOCK_EX);
  46. $jo = array(
  47. "type" => "error"
  48. );
  49. $j = json_encode ($jo);
  50. echo $j;
  51. return;
  52. }
  53. }
  54. }
  55. $files = "";
  56. foreach ($_SESSION['files'] as $key => $val) {
  57. $files .= "$key\n";
  58. }
  59. $j = json_encode ($jo);
  60. echo $j;
  61. file_put_contents("/tmp/log.txt", $j, FILE_APPEND | LOCK_EX);
  62. #error_log("\n\n ----- files ----- \n\n$files\n\n\n");
  63. #$xp = xvar_dump($_FILES);
  64. #error_log("\n\n ----- FILES ----- \n\n$$xp\n\n\n");