flightphp / core

An extensible micro-framework for PHP
https://docs.flightphp.com
MIT License
2.62k stars 409 forks source link

Upload file forms #468

Closed Flashtheorie closed 2 years ago

Flashtheorie commented 2 years ago

Hi everyone, How should I use move_uploaded_file with Flight ? As, when I use the usual :

move_uploaded_file($_FILES["new_avatar"]["tmp_name"][$i], "assets/img/photos_pre_inscription/" . $nouveauNom);

It's doing a 500

Capture d’écran 2022-04-08 à 12 30 14

Flashtheorie commented 2 years ago

Ok, so I managed to make it work using :

Flight::route('GET /uploadfile/@name', function($name){
    $_GET['file'] = $name;
    include 'views/assets/img/photos_pre_inscription/';
});

and

move_uploaded_file($_FILES["new_avatar"]["tmp_name"][$i], "uploadfiles" . $nouveauNom);

But it puts the files at the root of my project and with uploadfiles(sha1(name of the file) like :

uploadfiles3f7ddbe448683afb98c8436409456ef5

Not what I want 😄

Flashtheorie commented 2 years ago

Ok, I managed by myself by adding the destination into a variable

$destination = "assets/img/photos_pre_inscription/".$nouveauNom;
 move_uploaded_file($_FILES["new_avatar"]["tmp_name"][$i],$destination);