0
Good afternoon, for some time I have a problem, I have the following input of type file, to get some file any.
<form class="form-signin" method="post" action="?classe=Usuario&acao=pegaFoto">
<div class="form-label-group">
<input type="file" name="usuario[foto]" required>
</div>
<button class="btn btn-lg btn-primary btn-block text-uppercase" type="submit">Enviar</button>
<form>
When you click to give Ubmit, it will enter the same page, if there is any file inside the user[photo], it will call the function pegaFoto() in the controller.
public function pegaFoto(){
$usuario = new Usuario();
if( isset( $_POST['usuario'])){
$usuario->foto($_POST['usuario']);
$usuario->pegaFoto();
}
require_once 'views/view_foto.php';
}
This function of the controller calls the model’s call function() and also calls the photo() function where I would like to save the file path.
public function foto($usuario){
$this->foto = $usuario['foto'];
}
public function pegaFoto(){
//coloquei o echo só para ver o que estava puxando
echo $this->foto;
}
But the way I did, it just takes the name of the file chosen, I wonder if somehow I could take the file path.
Files sent to PHP are in
$_FILES
, not in$_POST
. You moved the file to a definitive location before treating it or you don’t need it?– Woss
I’ve never seen $_FILES, I’ll take a look here, you don’t need the definitive location, I just wanted to find the way for now.
– André Paiva
To send files ( $_FILES ) via your form, add the enctype="Multipart/form-data", e.g.: <form action=".. /. /" method="post" enctype="Multipart/form-data">
– ElvisP