1
Good afternoon,
I’m trying to list the files in a folder. After running Cod. below, the error occurs:
Parse error: syntax error, Unexpected 'as' (T_AS), expecting ')' in C: xampp htdocs 01-Signer testAssinador.php on line 23
Personally, I can’t see where the mistake is. Could someone help me? Thank you!
$_path = 'C:\xampp\htdocs\01-Signer\Fev19';
if(is_dir($_path)){
foreach(glob("$_path\*.txt") as $arquivo){
echo "Nome do Arquivo: <a href='$arquivo'>$arquivo</a><br />";
}
}else{
echo 'Não existe arquivo com extensão pdf.';
}
The result of
glob("$_path\*.txt")
you have to put into a variable, and use that variable in theforeach
– Edward Ramos
@Edwardramos Why you need to put in a variable?
– Woss
And what I saw in that question https://stackoverflow.com/questions/47805963/using-glob-to-get-txt-and-png-files-only-folder?noredirect=1&lq=1
– Edward Ramos
@Edwardramos The question is php. Python and PHP are different.
– Maury Developer
I put the glob("$_path*.txt") in a variable, but it still gives error (Parse error: syntax error, Unexpected 'as' (T_AS), expecting ')' in C: xampp htdocs 01-Signer testAssinator.php on line 26)
– user145547
@Renata https://www.php.net/manual/en/function.glob.php e https://www.electrictoolbox.com/php-glob-find-files/
– Maury Developer
@Renata Your code is correct, but it seems that there are invisible characters interfering with your file. Review how you’re writing the code or take care of where you copy and paste. I rewrote your code (https://repl.it/@acwoss/Allblushingratio) and it worked perfectly as expected.
– Woss
@Edwardramos Wanting to help is very good, don’t get me wrong, but helping by making baseless random guesses tend to get in the way of more than helping. If you’re not sure if you can solve the problem, test it first and see if it works. If it works, see if you can justify why you solved it. A solution without justification also doesn’t help much. I recommend repl.it for testing, just like I did above.
– Woss