<?php

use Mnv\Core\Config;
use Mnv\Core\Uploads\Uploader;
use Mnv\Core\Filesystem\FilesystemManager;

include('../../includes/overall.inc.php');
include('../../includes/admin-functions.inc.php');

/**
 * Загрузка изображений на сервер через редактор tinymce
 * uploading-file-to-content
 */
if (\request()->ajax()) {

    $path = request()->get('path', 'content');

    loadLanguage(Config::getValue('admin_language'));

    $filesystem = new FilesystemManager('/uploads', $path);
//    print_r($filesystem->realPath);
//    var_dump($filesystem->path);

    $upload = new Uploader('', $filesystem->realPath, $filesystem->path, 0);

    if ($upload->validate()) {
        $upload->upload();
    }
    $upload->response['flink'] = '';

    response()->json($upload->response, \Mnv\Http\Response::HTTP_OK, ['Content-Type' => 'application/json;charset=UTF-8', 'Charset' => 'utf-8'], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)->send();
    exit();

} else {

     die('Hacking attempt!');
}
