| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | require( dirname(__FILE__) . '/../../../wp-config.php' ); |
|---|
| 4 | if (!(is_user_logged_in() && current_user_can('edit_posts'))) |
|---|
| 5 | die("Athentication failed!"); |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | //print_r("Req\n"); |
|---|
| 9 | //print_r($_REQUEST); |
|---|
| 10 | //print_r("Files\n"); |
|---|
| 11 | //print_r($_FILES); |
|---|
| 12 | //print_r("Get\n"); |
|---|
| 13 | //print_r($_GET); |
|---|
| 14 | //print_r("Post\n"); |
|---|
| 15 | //print_r($_POST); |
|---|
| 16 | //$filepath = dirname(__FILE__) . '/files_flutter/log.txt'; |
|---|
| 17 | //file_put_contents($filepath, , FILE_APPEND); |
|---|
| 18 | |
|---|
| 19 | // |
|---|
| 20 | //Snipshot callback test |
|---|
| 21 | // |
|---|
| 22 | //Install this script on your server to test and debug callbacks from |
|---|
| 23 | //www.snipshot.com. Note: this script will need read and write access |
|---|
| 24 | //to your image directory. |
|---|
| 25 | |
|---|
| 26 | //CHANGE THIS TO THE DIRECTORY WHERE YOUR IMAGES WILL BE SAVED |
|---|
| 27 | $IMG_DIR = './files_flutter'; |
|---|
| 28 | chdir($IMG_DIR); |
|---|
| 29 | |
|---|
| 30 | //CHANGE THIS TO THE NAME OF THE FIELD THAT CARRIES THE IMAGE DATA OR URL |
|---|
| 31 | $OUTPUT = 'file'; |
|---|
| 32 | |
|---|
| 33 | function print_pre($r, $desc=''){ |
|---|
| 34 | echo '<pre>' . $desc . ' ' . print_r($r) . '</pre>'; |
|---|
| 35 | } |
|---|
| 36 | function glob_rsort_modtime( $patt ) { |
|---|
| 37 | if ( ( $files = @glob($patt, GLOB_BRACE) ) === false ) |
|---|
| 38 | return array(false, 'Glob error.'); |
|---|
| 39 | if ( !count($files) ) |
|---|
| 40 | return array(false, 'No files found.'); |
|---|
| 41 | $rtn = array(); |
|---|
| 42 | foreach ( $files as $filename ) |
|---|
| 43 | $rtn[$filename] = filemtime($filename); |
|---|
| 44 | arsort($rtn); |
|---|
| 45 | reset($rtn); |
|---|
| 46 | foreach ( $rtn as $filename => $t ) |
|---|
| 47 | $rtn[$filename] = date('r', $t); |
|---|
| 48 | return $rtn; |
|---|
| 49 | } |
|---|
| 50 | ?> |
|---|
| 51 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
|---|
| 52 | <html lang="en"> |
|---|
| 53 | <head> |
|---|
| 54 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|---|
| 55 | <title>Snipshot callback</title> |
|---|
| 56 | |
|---|
| 57 | <? |
|---|
| 58 | $operationSuccess = "false"; |
|---|
| 59 | if (!empty($_REQUEST)){ |
|---|
| 60 | //print_pre($_REQUEST, 'REQUEST'); |
|---|
| 61 | if (!empty($_FILES)){ //snipshot_callback_agent=snipshot |
|---|
| 62 | //print_pre($_FILES[$OUTPUT], 'FILES'); |
|---|
| 63 | move_uploaded_file( |
|---|
| 64 | $_FILES[$OUTPUT]['tmp_name'], |
|---|
| 65 | $_FILES[$OUTPUT]['name'] |
|---|
| 66 | );//file_put_contents($filepath, time()."trying ".$_FILES[$OUTPUT]['name']."\n", FILE_APPEND); |
|---|
| 67 | //file_put_contents("log.txt", time()."trying ".basename($_GET[$OUTPUT])); |
|---|
| 68 | } |
|---|
| 69 | else if (!empty($_GET[$OUTPUT])){ //snipshot_callback_agent=user |
|---|
| 70 | $data = file_get_contents($_GET[$OUTPUT]); |
|---|
| 71 | //echo "\nfrom ----".$_GET[$OUTPUT]."\n"; |
|---|
| 72 | $fp = fopen(basename($_GET[$OUTPUT]), 'wb'); |
|---|
| 73 | //echo "\nfrom ----".basename($_GET[$OUTPUT])."\n"; |
|---|
| 74 | fwrite($fp, $data); |
|---|
| 75 | fclose($fp); |
|---|
| 76 | chmod(basename($_GET[$OUTPUT]), 0644); |
|---|
| 77 | $filename = basename($_GET[$OUTPUT]); |
|---|
| 78 | |
|---|
| 79 | //$filename = 'hello_'.time() . '.jpg'; |
|---|
| 80 | //rename(basename($_GET[$OUTPUT]), $filename); |
|---|
| 81 | |
|---|
| 82 | $operationSuccess = "true"; |
|---|
| 83 | //file_put_contents("log.txt", var_export($_REQUEST, true)."\n new name = $filename\n",FILE_APPEND); |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | //$file_list = glob_rsort_modtime('{*.jpg,*.png,*.gif,*.tif,*.psd,*.pdf}'); |
|---|
| 88 | //$file_list = array_slice($file_list, 0, 10); |
|---|
| 89 | //print_pre($file_list, 'LAST 10 IMAGES'); |
|---|
| 90 | //foreach($file_list as $fn => $mt){ |
|---|
| 91 | // echo '<p><img src="'.$fn.'"/>'; |
|---|
| 92 | //} |
|---|
| 93 | ?> |
|---|
| 94 | </head> |
|---|
| 95 | <body> |
|---|
| 96 | |
|---|
| 97 | <script language="javascript"> |
|---|
| 98 | |
|---|
| 99 | var par = window.parent.document; |
|---|
| 100 | |
|---|
| 101 | if (<?php echo $operationSuccess?>){ |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | </script> |
|---|
| 108 | <h3> The file was updated successfuly</h3> |
|---|
| 109 | <p> Please save the page in order to see the changes. <a href="" onclick="self.parent.tb_remove();">Close this window</a> </p> |
|---|
| 110 | </body> |
|---|
| 111 | </html> |
|---|