Skip to content

Commit

Permalink
[PHP] increase max uploaded file size
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano committed Nov 5, 2024
1 parent fd7eb65 commit 8e1f8c9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docker/dev/nginx_proxy.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
client_max_body_size 100M;

proxy_connect_timeout 6003;
proxy_send_timeout 3600;
proxy_read_timeout 3600;
send_timeout 3600;
2 changes: 2 additions & 0 deletions docker/php/conf.d/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ apc.enable_cli = On
session.use_strict_mode = 1
zend.detect_unicode = 0
intl.default_locale = fr
upload_max_filesize = 15M
post_max_size = 20M
22 changes: 19 additions & 3 deletions src/Controller/Api/FormationUploadFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,40 @@

use App\Entity\AdherentFormation\Formation;
use App\Formation\FormationHandler;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Validator\ValidatorInterface;

class FormationUploadFileController extends AbstractController
{
public function __invoke(Request $request, Formation $formation, FormationHandler $formationHandler): Formation
{
public function __invoke(
EntityManagerInterface $entityManager,
ValidatorInterface $validator,
Request $request,
Formation $formation,
FormationHandler $formationHandler,
): Response {
$uploadedFile = $request->files->get('file');

if (!$uploadedFile) {
throw new BadRequestHttpException('Key "file" is required');
}

$errors = $validator->validate($uploadedFile, [new File(maxSize: '10M')]);

if ($errors->count()) {
return $this->json($errors, 400);
}

$formation->setFile($uploadedFile);

$formationHandler->handleFile($formation);
$entityManager->flush();

return $formation;
return $this->json('OK');
}
}
2 changes: 1 addition & 1 deletion src/DataFixtures/ORM/LoadAdherentFormationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private function createFile(Formation $formation): void
$this->formationHandler->handleFile($formation);
}

public function getDependencies()
public function getDependencies(): array
{
return [
LoadAdminData::class,
Expand Down

0 comments on commit 8e1f8c9

Please sign in to comment.