Honesty Rocks! truth rules.

Iframe Src = A Local File In My Computer

HOME      >>       Programming


Is it possible to call a file, i.e. 1.htm, from my web browser using such tag


<iframe src="file:///C:/1.htm"> </iframe>


file:///C:/1.htm is the correct path since when I enter it to my web browser's address box it shows up properly. But when I use the same call function in my PHP it does not.


My situation is that I'm running Apache with PHP, therefore I am running my own mimi-webserver on my computer. There's no risk of someone else accessing my file because it's for my testing purpose.


I thought it had to do with some Apache setting but I cannot seem to overcome this obstacle. Any HTML or Apache gurus out there, if you have a solution to call localized file to a browser using any HTML markup I would be appreciated :o


I once saw an advertisement for anti-spyware that loaded my C: drive into an iframe—quite ingenious i might add. But the code you provided in the HTML bbcode should work in the browser, since you're providing the absolute path. In PHP, you do not include "file:///" in functions or statements; in print and echo statements it's optional. I am unsure of any other possible reasons why it would not work.



seems that the html file you call needs to be accessible from your local web server and the http protocol needs to call the file.

<iframe src="http://localhost/char_test.php" width="640" height="400" /></iframe>

Works for me in my localhost from an html file, and the php inside the iframe gets properly parsed, too.


Browsers since IE5 and such alike have released a security patch to prevent IFRAME from opening local file--as truefusion mentioned why it was necessary.

I am trying to circumvent this restriction and perhaps only allow 'localhost' to access files outside of 'htdocs.'

htdocs is the default folder set by Apache to store and view server files (C:/Program Files/Apache/htdocs). Only files within htdocs, aka localhost, can be accessed using http: //localhost/... This is so that if your computer is servicing web files, you wouldn't want outside browsers to view any of servers root files/folders. So anytime //localhost/folder/file is called it is still within the confines of htdocs folder.

Apache configuration allows me to change where 'htdocs' is located but I do not want to set it as C:/ This is dangerous. And since localhost cannot call external files, i.e. outside of C:/Program Files/Apache/htdocs, due to

You don't have permission to access C:/1.htm on this server.

is there a clever way to access restricted files on the server from a local browser?


Hmm, I am not quite sure, but you could possibly use a Perl script or something similar. I really don't see how you can. I don't think you can do it though because of Apache's configuration of htdocs being your folder for the server to look through. I could be wrong though.EDIT: I just thought of a possible way to temporarily put the file inside htdocs. You can use a FTP server and the FTP functions in PHP to put and get the file from a FTP server and delete them. That could work.


is there a clever way to access restricted files on the server from a local browser?

It may have to do with your PHP.ini configuration. I remember once during testing of one of my scripts where i tried to include a file outside of my DocumentRoot: it gave me access denied, saying that i could not access files outside of my DocumentRoot. Browsing the PHP.ini configuration, i noticed that the section "Paths and Directories" had include_path commented out. I uncommented that line for my operating system, included the directory i wanted access to, and restarted the Apache server. This allowed me to include a file outside of my DocumentRoot. Try this out and see if it helps.


coolcat50,Nice work around! Although I barely got it to work, certainly it was one of solutions.truefusion,Brilliant! Instead of just HTML I guess I can use PHP to include files. It worked like a charm. And now to rewrite the code :o


Replying to BuffaloHELPCan you help show your code? How do you tell it to use the external source instead of the htdocs?-question by Chad


How to write html code for local harddrive accessIframe Src = A Local File In My Computer

Hi, I confess to not being a computer genius but have maintained web sites for many years. I want to expand my web site to include videos and mp3 files, but they are way to large to send up to my server and the cost would be prohibiting. So, I would simply like to run the videos from my hard drive but link to them from my web site. It "sounds" simple enough, but then what do I know. I am trying to build my own server to run from home, but the wealth of information seems to be way over my head, so a simple link code would probably work for me, at least for now. Any ideas or suggestions would be greatly appreciated.



local files - some work, some donIframe Src = A Local File In My Computer


I'm not sure whether to start a new thread or if this is similar enough to justify adding here (which I believe is encouraged on these forums?)

I'm trying to create *.Hta "launchers" for *.Swf files (games, music utilities, etc.) stored on my HD.   Some of these swf files open just fine, but others cause IE to display the annoying "To help protect your security, Internet Explorer has restricted this webpage from running scripts or ActiveX controls that could access your computer.  Click here for options..." message.  So I found that HTA's were trusted and am trying to put an HTA in the same directory as its corresponding SWF. 

Here is my "template" HTA launcher:

<HTML><HEAD><TITLE>metronome</TITLE><HTA:APPLICATION ID="oMyApp"   BORDER="thick"   INNERBORDER="no"   SCROLL="auto"   CAPTION="yes"   SHOWINTASKBAR="yes"   SINGLEINSTANCE="yes"   SYSMENU="yes"   WINDOWSTATE="normal"><STYLE> body {margin:0} </STYLE></HEAD><BODY><IFRAME src="metronome.Swf" application=yes width="100%" height=100% marginwidth=0 marginheight=0 frameborder=0>Iframes not supported</IFRAME></BODY></HTML>

But it seems to sometimes work and sometimes not.  I have some SWF's that normally trigger the above "restricted" message in IE, but work fine from an HTA; on the other hand, I have several that don't trigger that message in IE, but don't work at all from an identically coded HTA.  They get the following two error messages:"An error has occurred in the script on this page.Line: 2Char: 1Error: Invalid characterCode: 0URL: file:///C:/Users/Username/Desktop/Program%20Files%20(portable)/programs/music%20utils%20(in%20Flash)/metronome.SwfDo you want to continue running scripts on this page?" (Y/and)

"An error has occurred in the script on this page.Line: 1Char: 1Error: Object expectedCode: 0..."

They can be in the exact same folder (on C:).  But, I move the ones that don't work to a flash drive (E:), and they work from there!

So is the problem related to the drive?  Whether the original SWF triggers the IE "restricted" message or not?  ...  And how can I fix it?