Beispiel #1
0
/**
 * Get file informations (size, name ...)
 *
 * @param Application $app Silex Application
 * @param Request $request Request parameters
 *
 * @return JsonResponse Object containing file informations
 */
function get_infos(Application $app, Request $request)
{
    if ($app["rights.canPlayMedia"] == false) {
        $app->abort(403, "This user doesn't have the rights to retrieve file informations");
    }
    $filepath = Utils\check_path($app['cakebox.root'], $request->get('path'));
    if (!isset($filepath)) {
        $app->abort(400, "Missing parameters");
    }
    $file = new \SPLFileInfo("{$app['cakebox.root']}/{$filepath}");
    $fileinfo = [];
    $fileinfo["name"] = $file->getBasename("." . $file->getExtension());
    $fileinfo["fullname"] = $file->getFilename();
    $fileinfo["mimetype"] = mime_content_type($file->getPathName());
    $fileinfo["access"] = str_replace('%2F', '/', rawurlencode("{$app['cakebox.access']}/{$filepath}"));
    $fileinfo["size"] = $file->getSize();
    return $app->json($fileinfo);
}