2
I’m trying to make a scandir of a directory that will be filtered by a variable that contains the name of the file (without the extension) however I have no idea how to accomplish this, follows an example:
$nome = $_POST["imgname"];//nome do arquivo recebido pelo post
$dir = "pasta/img/";//Local onde o arquivo está salvo
$arquivo = scandir($dir);//Pedaço que gostaria de modificar para filtrar pelo $nome
OBS: I’m doing scandir to get the file extension because as I said above the variable $nome
does not have extension, if there is another way to get the full name of the specified file would help a lot too!
Simpler than I thought, thanks for the hint, but why put {} in the variables? From what I tested he returned the same value to me with or without them, has some specific reason?
– Wel
@Wel just to improve reading and not to be using
"texto" . $var . "texto"
. This allows me to use"texto{$var}text"
, so PHP will know the limit of the variable. If there were no{}
, PHP would think that the variable is$vartext
.– Valdeir Psr