foverzar foverzar - 9 months ago 112
PHP Question

Catch uploaded file name in Fat Free Framework

My php script has to handle with non-slug filename uploads, when for example, a user tries to upload a file "Имя на русском.jpg". Some methods don't handle it correct, so i use:

$overwrite = true;
$slug = true;

So, I get the "imja-na-russkom.jpg" file on server. The problem is that I need to catch this filename for DB, for which I tried this:

$filename = \Web::instance()->Slug($_FILES['userfile']['name'];

Which returns "imja-na-russkom-jpg" - not the name used in filesystem (not dot, but dash before extension).

So, my question is: Is there a way to catch the name, used in Web::receive() or, if not, is there a workaround to get it by means of F3? Thank you.


Ok, with ikkez' tip i figured that out:

$a = Web::instance()->receive(NULL,true,true);
$name = array_keys($a);
$name = pathinfo($name['0'], PATHINFO_BASENAME);

Here we upload file on the server and save it's name into $name variable. You can skip the last line and use

$name = $name['0'];

if you want to save the full path to your uploaded file.