Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> PHP Screenshot
timez
post
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 1.07.2016

Ostrzeżenie: (0%)
-----


Witam serdecznie, poszukuje już od kilku dni i nie mogę znaleźć.. Potrzebuję mieć zwykły przycisk który po kliknięciu będzie wyświetlać gdzie chce zapisać dany obraz /png. Znalazłem tutaj jedno ale nie działa mi niestety..
  1. function take_screenshot()
  2.  
  3. {
  4. html2canvas(document.body, {
  5. onrendered: function(canvas)
  6. {
  7. var img = canvas.toDataURL()
  8. $.post("save_screenshot.php", {data: img}, function (file){
  9. window.location.href = "save_screenshot.php?file="+ file
  10. });
  11. }
  12. });
  13. }

PHP
  1. <?php
  2.  
  3. if($_GET['file'])
  4. {
  5. $file=$_GET['file'];
  6. if (file_exists($file))
  7. {
  8. header('Content-Description: File Transfer');
  9. header('Content-Type: image/png');
  10. header('Content-Disposition: attachment; filename='.basename($file));
  11. header('Content-Transfer-Encoding: binary');
  12. header('Expires: 0');
  13. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  14. header('Pragma: public');
  15. header('Content-Length: ' . filesize($file));
  16. flush();
  17. readfile($file);
  18. unlink($file);
  19. }
  20. }
  21.  
  22. if($_POST['data'])
  23. {
  24. $data = $_POST['data'];
  25. $file = md5(uniqid()) . '.png';
  26. $uri = substr($data,strpos($data,",")+1);
  27. file_put_contents('./'.$file, base64_decode($uri));
  28. echo $file;
  29. exit();
  30. }
  31. ?>


Piszę pracę o Leap Motion, mam dane ćwiczenie które rysuje i po tym kończy się zadanie i button się wyświetla. Ale gdy go klikam niestety nic się nie dzieje a zależy mi mega by się mógł zapisać screen.. Bardzo was proszę pomoc!
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
timez
post
Post #2





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 1.07.2016

Ostrzeżenie: (0%)
-----


mam tak nazwane, mam zaimplementowaną bibliotekę, zmieniłem tam ale nadal niestety nie działa. Nawet jak robię na sucho, 2 pliki. Jeden z html a drugi php. włączam przez przeglądarke i mam przycisk button, klikam na niego ale niestety nic się nie robi.
  1. <script type="text/javascript" src="jquery.js"></script>
  2. <script src="html2canvas.js" type="text/javascript"></script>
  3. function take_screenshot()
  4. {
  5. html2canvas(document.body, {
  6. onrendered: function(canvas)
  7. {
  8. var img = canvas.toDataURL()
  9. $.post("save_screenshot.php", {data: img.split(',').pop()}, function (file){
  10. window.location.href = "save_screenshot.php?file="+ file
  11. });
  12. }
  13. });
  14. }
  15. <div id="wrapper">
  16. <div id="screenshot_div">
  17. <button type="button" onclick="take_screenshot()">Take Screenshot</button>
  18. </div>
  19. </div>
  20. </body>
  21. </html>

  1. <?php
  2. if($_GET['file'])
  3. {
  4. $file=$_GET['file'];
  5. $file = './tmp/'.str_replace(array('/', '\\', '..'), '', $file);
  6. if (file_exists($file))
  7. {
  8. header('Content-Description: File Transfer');
  9. header('Content-Type: image/png');
  10. header('Content-Disposition: attachment; filename='.basename($file));
  11. header('Content-Transfer-Encoding: binary');
  12. header('Expires: 0');
  13. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  14. header('Pragma: public');
  15. header('Content-Length: ' . filesize($file));
  16. flush();
  17. readfile($file);
  18. unlink($file);
  19. }
  20. }
  21.  
  22. if($_POST['data'])
  23. {
  24. $data = $_POST['data'];
  25. $file = md5(uniqid()) . '.png';
  26. $uri = substr($data,strpos($data,",")+1);
  27. file_put_contents('./tmp/'.$file, base64_decode($uri));
  28. echo $file;
  29. exit();
  30. }
  31. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 4.10.2025 - 15:50