ninegitea/src/Controller/HomeController.php

51 lines
1.4 KiB
PHP
Raw Normal View History

2021-07-20 13:04:47 +02:00
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Filesystem\Filesystem;
class HomeController extends AbstractController
{
public function home()
{
return $this->redirectToRoute("app_scrum");
}
public function admin()
{
return $this->render('Home/admin.html.twig',[
"useheader" => true,
"usesidebar" => true,
]);
}
public function upload(Request $request,$access=null) {
// Fichier temporaire uploadé
$tmpfile = $request->files->get('upload');
$extention = $tmpfile->getClientOriginalExtension();
// Répertoire de Destination
$fs = new Filesystem();
$rootdir = $this->getParameter('kernel.project_dir') . '/public';
$fs->mkdir($rootdir."/uploads/ckeditor");
// Fichier cible
$targetName = uniqid().".".$extention;
$targetFile = $rootdir."/uploads/ckeditor/".$targetName;
2023-12-22 13:53:10 +01:00
$targetUrl = $this->getParameter('appAlias')."uploads/ckeditor/".$targetName;
2021-07-20 13:04:47 +02:00
$message = "";
move_uploaded_file($tmpfile,$targetFile);
$output["uploaded"]=1;
$output["fileName"]=$targetName;
$output["url"]=$targetUrl;
return new Response(json_encode($output));
}
}