Example #1
0
    outputJSON(i18n::s('Request is invalid.'));
} else {
    $name = $_REQUEST['name'];
}
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
// Output JSON
function outputJSON($msg, $status = 'error', $preview = '')
{
    global $context;
    Js_css::prepare_scripts_for_overlaying();
    $js = $context['javascript']['footer'];
    header('Content-Type: application/json');
    die(json_encode(array('data' => $msg, 'status' => $status, 'preview' => $preview, 'js' => $js)));
}
load_skin();
safe::make_path('temporary/uploaded/');
// we need a file
if (isset($_FILES[$name]) && count($_FILES[$name])) {
    // Check for errors
    if ($_FILES[$name]['error'] > 0) {
        Safe::header('Status: Internal 500 server error', TRUE, 500);
        outputJSON(i18n::s('An error ocurred when uploading.'));
    }
    /*if(!getimagesize($_FILES['SelectedFile']['tmp_name'])){
          outputJSON('Please ensure you are uploading an image.');
      }*/
    // Check filetype
    if (!Files::is_authorized($_FILES[$name]['name'])) {
        Safe::header('Status: 415 Unsupported media', TRUE, 415);
        outputJSON(i18n::s('Unsupported filetype uploaded.'));
    }