scratch – Rev

Subversion Repositories:
Rev:
<?php

###########################################################################
##  Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3      ##
###########################################################################

require_once('inc/pseudocrypt.php');
require_once('inc/functions.php');
require_once('config.php');

#### Build the user path.
$userPath = join(
    DIRECTORY_SEPARATOR,
    array(
        $STORE_FOLDER,
        $SHARED_EDITOR_FILE
    )
);

#### Check for path traversals
$pathPart = pathinfo($userPath);
if (strcasecmp(
    realpath($pathPart['dirname']), realpath($STORE_FOLDER)) != 0)
    return;

switch($_SERVER['REQUEST_METHOD']) {
    case 'POST':
        #### Retrieve uploaded file.
        if(!isset($_POST['data']) or empty($_POST['data']))
            return;
            
        #### Store the file.
        atomized_put_contents($userPath, $_POST['data']);
        break;
    case 'GET':
        if(!file_exists($userPath))
            return;
        header('Content-Type: text/html; charset=utf-8');
        echo atomized_get_contents($userPath);
        break;
}