save.php 1.22 KB
<?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
    // Get the data
    $imageData=$GLOBALS['HTTP_RAW_POST_DATA'];
 
    // Remove the headers (data:,) part. 
    // A real application should use them according to needs such as to check image type
    $filteredData=substr($imageData, strpos($imageData, ",")+1);
 
    // Need to decode before saving since the data we received is already base64 encoded
    $unencodedData=base64_decode($filteredData);
 
    //echo "unencodedData".$unencodedData;
 
    // Save file.  This example uses a hard coded filename for testing,
    // but a real application can specify filename in POST variable
    
    // Ñîçäàåì ïàïêó
        $root=$_SERVER['DOCUMENT_ROOT']."/";
        
    if (!is_dir($root."xml/".date('Y'))) {
        mkdir($root."xml/".date('Y'), 0777, true);
        chmod($root."xml/".date('Y'), 0777);
    }
    
    if (!is_dir($root."xml/".date('Y')."/".date('m'))) {
        mkdir($root."xml/".date('Y')."/".date('m'), 0777, true);  
        chmod($root."xml/".date('Y')."/".date('m'), 0777);
    }
                
    $fp = fopen($root.'xml/'.date('Y').'/'.date('m').'/grafic_report_'.date('Y-m').'-'.(date('d')-1).'.png', 'w' );
    fwrite( $fp, $unencodedData);
    fclose( $fp );
}
?>