How to get a filename from a file upload to save into database field?

128 views
Skip to first unread message

GauravK

unread,
Apr 14, 2017, 12:17:15 PM4/14/17
to Fat-Free Framework
How do you get the file name from a file upload? I am trying to save the filename into a database field called 'images' but the last line does not work. The file upload itself works (I can see the new file in the upload folder) and the rest of the database information is saved except the filename.

function save($f3){    
   
// save the user's results to the database
    $newquiz
= new Quizzes ($this->db);
   
   
// set the web file receive method
    $web
= new \Web();
    $overwrite
=true;
    $slug
= true;


    $newquiz
->copyfrom('POST', function($val) {
       
return array_intersect_key($val, array_flip(array('name','description')));
   
});
    $files
= $web->receive(function($file,$formFieldName){
        var_dump
($file);
       
return true;
   
},
    $overwrite
,
    $slug
 
);
 $newquiz
->image = $files[0]; // this line does not work
 $newquiz
->save();
....
}

GauravK

unread,
Apr 14, 2017, 12:21:42 PM4/14/17
to Fat-Free Framework

Fernando Magrosoto Vásquez

unread,
Oct 9, 2020, 12:16:33 PM10/9/20
to Fat-Free Framework
I have a script where can clean the name of the file.
I don`t know why, but the file is upload with te correct name, but the return name of the uploaded file is concatenated with the UPLOADS directory.
Thus, I have to clean the returned name before save it into a table of my DataBase.

// Almacenar y grabar PDF e imágenes
$this->f3->set('UPLOADS', 'almacen/' . $registro->token . '/');
\Web::instance()->receive(function($archivo, $campo){
$tipoArchivo = \Helpers\LimpiarNombreArchivo::campoEntrada($campo);
$tabla = 'tbl_';
$tabla .= ($tipoArchivo == 'foto') ? 'fotos' : $tipoArchivo;
$regArchivo = new \DB\SQL\Mapper(\Helpers\ConXion::link(), $tabla);
$regArchivo->$tipoArchivo = \Helpers\LimpiarNombreArchivo::nombreArreglo($archivo['name']);
$regArchivo->inmueble = \Helpers\LimpiarNombreArchivo::extraerID($campo);
$regArchivo->save();
}, true, function($nombre, $campo){
return \Helpers\LimpiarNombreArchivo::nombreEntrada($nombre, $campo);
});

So, the name of upload file and the return name will be the same.
Reply all
Reply to author
Forward
0 new messages