Guest User

Documenter Save Handler

a guest
Sep 7th, 2011
3,815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1. <?php
  2. /*----------------------------------------------------------------------*/
  3. /** This program is free software. It comes without any warranty, to
  4.   * the extent permitted by applicable law. You can redistribute it
  5.   * and/or modify it under the terms of the Do What The Fuck You Want
  6.   * To Public License, Version 2, as published by Sam Hocevar. See
  7.   * http://sam.zoy.org/wtfpl/COPYING for more details.
  8.   *
  9.   * version 1.0
  10.   *
  11.   * This is simple script which handles the advanced options from
  12.   * the Documenter. This is just to give you an idea what you can do
  13.   * and how it works.
  14. /*----------------------------------------------------------------------*/
  15.  
  16.  
  17. //delete this line if you don't like to use a password but keep in mind others can send files to this script as well so I not recommend it
  18. if($_POST['pwd'] != md5('YOUR_SUPER_SECRET_PASSWORD')){exit;}
  19.  
  20.  
  21. //if a json POST variable is set
  22. if(isset($_POST['json'])){
  23.     //get rid of some chunk
  24.     $filename = 'documentation.json';
  25.     $json = str_replace('\\\\','\\',str_replace('\\"','"',$_POST['json']));
  26.     //and save it somewhere
  27.     write($filename,$json);
  28.     //output the URL of the JSON (required for the save function)
  29.     echo 'http://docs.revaxarts.com/'.$filename;
  30.     exit;
  31. }
  32.  
  33. //we have a file upload
  34. if(!empty($_FILES)){
  35.     //handle it as a fileupload
  36.     move_uploaded_file($_FILES["file"]["tmp_name"], $_FILES["file"]["name"]);
  37. }
  38.  
  39.  
  40. //file_put_contents doesn't work everywhere
  41. function write($filename, $data = ''){
  42.     if (!$handle = fopen($filename, "w+")) {
  43.         return false;
  44.         exit;
  45.     }
  46.     if (!fwrite($handle, $data)) {
  47.         return false;
  48.         exit;
  49.     }
  50.  
  51.     fclose($handle);
  52.     return true;
  53. }
  54.  
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment