ofc_upload_image.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. //
  3. // In Open Flash Chart -> save_image debug mode, you
  4. // will see the 'echo' text in a new window.
  5. //
  6. /*
  7. print_r( $_GET );
  8. print_r( $_POST );
  9. print_r( $_FILES );
  10. print_r( $GLOBALS );
  11. print_r( $GLOBALS["HTTP_RAW_POST_DATA"] );
  12. */
  13. // default path for the image to be stored //
  14. $default_path = '../tmp-upload-images/';
  15. if (!file_exists($default_path)) mkdir($default_path, 0777, true);
  16. // full path to the saved image including filename //
  17. $destination = $default_path . basename( $_GET[ 'name' ] );
  18. echo 'Saving your image to: '. $destination;
  19. // print_r( $_POST );
  20. // print_r( $_SERVER );
  21. // echo $HTTP_RAW_POST_DATA;
  22. //
  23. // POST data is usually string data, but we are passing a RAW .png
  24. // so PHP is a bit confused and $_POST is empty. But it has saved
  25. // the raw bits into $HTTP_RAW_POST_DATA
  26. //
  27. $jfh = fopen($destination, 'w') or die("can't open file");
  28. fwrite($jfh, $HTTP_RAW_POST_DATA);
  29. fclose($jfh);
  30. //
  31. // LOOK:
  32. //
  33. exit();
  34. //
  35. // PHP5:
  36. //
  37. // default path for the image to be stored //
  38. $default_path = 'tmp-upload-images/';
  39. if (!file_exists($default_path)) mkdir($default_path, 0777, true);
  40. // full path to the saved image including filename //
  41. $destination = $default_path . basename( $_FILES[ 'Filedata' ][ 'name' ] );
  42. // move the image into the specified directory //
  43. if (move_uploaded_file($_FILES[ 'Filedata' ][ 'tmp_name' ], $destination)) {
  44. echo "The file " . basename( $_FILES[ 'Filedata' ][ 'name' ] ) . " has been uploaded;";
  45. } else {
  46. echo "FILE UPLOAD FAILED";
  47. }
  48. ?>