If the file is on the server and a user must select a file to attach then what you should do is list the files of a certain folder.
You can use the following script to achieve it.
$directorio = opendir("."); //ruta actual
while ($archivo = readdir($directorio)) //obtenemos un archivo y luego otro sucesivamente
{
if (is_dir($archivo))//verificamos si es o no un directorio
{
echo "[".$archivo . "]<br />"; //de ser un directorio lo envolvemos entre corchetes
}
else
{
if (strpos($archivo,".txt") !== false)
{
echo $archivo . "<br />";
}
}
}
Then it is up to you with what shape the results are printed. If in a SELECT, in a messy list, etc.
I limit that only files with .txt format are printed, but you can modify it or directly remove it. If you do not want the folders to print, you must use the code as well.
$directorio = opendir("."); //ruta actual
while ($archivo = readdir($directorio)) //obtenemos un archivo y luego otro sucesivamente
{
if (!is_dir($archivo))//verificamos si es o no un directorio
{
if (strpos($archivo,".txt") !== false)
{
echo $archivo . "<br />";
}
}
}