List folder with files extension htm and open in new page

Asked

Viewed 206 times

0

Daily I receive files with extension in ". htm" with information I need to open to view and, always use the right mouse button feature and 'open with' and choose the browser. Thus: arquivotexto1.htm arquivotexto2.htm arquivotexto3.htm

Detail: file names always vary, but the extension is always '.htm'


I tried to make this code:

<?php
// diretório onde estão os arquivos
$diretorio = "c:\diretorio\mes_e_Ano";

// *.txt são os formatos de arquivos a serem alterados
foreach (glob("$diretorio/*.*") as $arquivo) {
$p1 = explode("/", $arquivo);
$p2 = explode(".", $p1[1]);
//print "<a href=\"$arquivo\" target=\"_blank\">$p2[0]</a><br>";
//print "<a href=\"#\" onclick=\"window.open('$arquivo','_blank','')\">$p2[0]</a><br>";
print "<a href=\"#\" onclick=\"window.open('http://nomeservidor/mes_e_ano/','$arquivo','')\">$p2[0]</a><br>";
}

?>

even opens the file view. I can see it. But when I click on them, it shows an error that does not exist. 'Forbidden'

If you change the parameter on the server, in the "Options -Indexes", putting a "#" in front it starts to display and works, but the correct thing is to keep the parameter for security reasons by observing.

I would like to know how to do it when you click on the symbolic link, now open automatically, without having to disable the parameter.

If anyone can assist, I’d appreciate

  • Open the file directly in window.open like this: window.open('http://hostname/mes_e_ano/$file')

  • hello! thanks for feedback! In case, I did this way now:

  • Hello! Thank you! Thank you! In this case, I made this change(line) this way now: ---- ('http://hostname:port/mes_e_year/$file',')">$P2[0]</a><br>"; } ---- Displays a message like this, after clicking on the link name , in case 0109.htm: Forbidden You don’t have permission to access /month e_year/c:directormes_e_ano/0109.htm on this server. if I type directly the following line in the browser: http://hostname:port/mes_e_ano/0109.htm => opens normally with no problems There must be something missing in the code. I wait if anyone can assist.

  • Dude... that way, the error is not in the programming but in the path that PHP is mounting. Check this out.

  • good day! I noticed that in the variable '$file', the full path is coming and not only the name of the file. That could be it. I have not yet found the correct way to make the note. any suggestion ?

  • Use the scandir function instead of GLOB, you can solve! $files=scandir($directory); foreach($files as $file){ ... }

  • hello! I thank you and will make the change to scandir. Still in the other original form, I did so and, it worked. By the hint you gave about the path, I changed the access parameters of the vector position. Thank you very much! Now accessed: ____ <? php // directory where the files $directory = "c: name_year folder"; ;// .txt are the file formats to be changed foreach (glob("$directory/.htm") as $file) { $P1 = explodes("/", $file); $P2 = explodes("." , $P1[1]); print "<a href="#" onclick="window.open('http://hostname:port/mes_e_year/$P1[1]',')">$P2[0]</a><br>"; } ?>

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.