1

I need to show files that I have in a listing files and directories in mi < iframe > This is my listinf files code:

$directorioInicial = "./";   
$rep = opendir($directorioInicial);    
echo "<ul>";
while ($todosArchivos = readdir($rep)) {  
if ($todosArchivos != '..' && $todosArchivos != '.' && $todosArchivos != '')     {
    echo "<li>";
     echo "<a href=" . $directorioInicial . "/" . $todosArchivos . "         target='_blank'>" . $todosArchivos . "</a><br />"; 
    echo "</li>";
}
}
closedir($rep);      
clearstatcache();     
echo "< /ul>";

I need to do click in the file that I show in my list and the file will be show in my frame, but I dont know how...At the momento I show the file in another page... But it's not what I need... Thank you... This is my frame:

<iframe id="probando" src="<?php echo $url; ?>" scrolling="auto" height="700" width="800" marginheight="0" marginwidth="0" name="probando"></iframe>
Luis
  • 69
  • 1
  • 11
  • 1
    `target="_blank"` will open a hyperlink in new window .. Remove it if you want to open the page within your `iframe` itself – Makesh May 19 '15 at 07:51
  • Because of security reasons, [modern browsers do not allow to show local files](http://kb.mozillazine.org/Links_to_local_pages_don%27t_work). Because page generated by PHP (even on `localhost`) is external scope, you will not be able to show the file within an `IFRAME` – Voitcus May 19 '15 at 07:52
  • Yep, I know but I dont know how I send to my iframe – Luis May 19 '15 at 07:52
  • I show all the files that I have in my directories but when I click one of these files.html open me a new web page... My question is How I send to my active iframe... – Luis May 19 '15 at 07:54
  • @LewiSS88 Makesh gave you the answer: delete `target='_blank'`, but check also [this question](http://stackoverflow.com/q/1254572/2088851) – Voitcus May 19 '15 at 08:00
  • If I delete the target='_blank' , I just show the web page in the same page but not in my iframe... I tryed – Luis May 19 '15 at 08:02
  • Little bit confusing ... So whatever link you are clicking from a page need to be opened in a `iframe` within the same page. Is it your problem? – Makesh May 19 '15 at 08:40

1 Answers1

1

Name a iframe and set that name in target attribute of the hyperlink.

Try this :

$directorioInicial = "./";   
$rep = opendir($directorioInicial);    
echo "<ul>";
while ($todosArchivos = readdir($rep)) {  
if ($todosArchivos != '..' && $todosArchivos != '.' && $todosArchivos != '')     {
    echo "<li>";
     echo "<a href=" . $directorioInicial . "/" . $todosArchivos . "         target='probando'>" . $todosArchivos . "</a><br />"; 
    echo "</li>";
}
}
closedir($rep);      
clearstatcache();     
echo "< /ul>";


<iframe id="probando" src="<?php echo $url; ?>" scrolling="auto" height="700" width="800" marginheight="0" marginwidth="0" name="probando"></iframe>

More : http://www.w3schools.com/html/html_iframe.asp

Makesh
  • 1,236
  • 1
  • 11
  • 25
  • Good answer but what I need its to put any file.html not pre-definited files or directions... I mean someone file that previusly was save in the designed folder. – Luis May 19 '15 at 09:22
  • 1
    Are you trying to implement something in this img : http://www.phpf1.com/images/maxFileBrowser/maxFileBrowser.png .. So, when you click "list content", you need to display the files in your `iframe` ? – Makesh May 19 '15 at 09:26
  • Yes I have an iframe that show me one web page, on the header I have a list of files.html and I need that when I do it "click" on any of these .html change me what iframe shows. I think maybe I have to change the "src" of the iframe... or something like that – Luis May 19 '15 at 09:32
  • And how I integrate these code on mu php code? Is not valid my code for do it this action? – Luis May 19 '15 at 09:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/78166/discussion-between-makesh-and-lewiss88). – Makesh May 19 '15 at 10:04