How to make apache serve file:/// - php

I'm kind of new to HTML, PHP and stuff.
I'm trying to test locally a web site before putting it online. I set up my Apache server with PHP and MySQL and made a virtual server point localhost to
"C:/path/to/docroot/"
and everything works great.
Now in my index.html I have a link pointing to the file "mail-form.php" in the same directory (the C:/path/to/docroot/). In this link I only specified
href="mail-form.php"
and no absolute path, because I don't know which would be the absolute path in the production server and I don't feel like changing them all after testing. (Here I'm open for suggestions, if this is bad).
Now the thing I don't understand is the following: when I type in the browser's URL
"file:///C:/path/to/docroot/index.html"
and then click on the link, the browser tries to open
"file:///C:/path/to/docroot/mail-form.php"
and this doesn't get interpreted by PHP, but returned as text.
If I instead type in
"localhost/index.html"
and then click on the link, the browser calls
"localhost/mail-form.php"
and it gets interpreted properly showing what it should.
I can obviously live with this, but I'm curious if there is a way to make Apache/PHP serve the "file:///..." thing just as well as the "localhost/..." thing? After all they are both the same file. Or is it a browser problem? Or am I thinking wrong?

You can't make Apache serve file:///. Using that scheme instructs the browser to fetch the file directly from the filesystem. If you want to use Apache then you have to use http:// (or another URL scheme that makes a network request that Apache supports).

No. The file:/// protocol is not HTTP. The browser won't even send it to the localhost server you're running, and instead just read the file.

Related

How to configure local PHP to show directory content

I have a local version of Windows php to test my webpage. I run it using php.exe. It has a built-in webserver so pages can be accessed from a browser through localhost:/path.
If I enter an URL pointing to a file it opens that file in browser. I would like to configure it so that it shows the content of a directory if URL points to a directory. E.g. after inserting URL http://localhost:1234/foo/bar/ into the browser I would want to see the files in the bar directory listed in the browser. Similarly how other webservers do it when configured so.
My local PHP returns 404 instead.
Is there any way how to achieve that for this built-in webserver in php.exe? How?
The built-in server is specifically for quick development and debugging as stated in the command line server doc and directory listing is one of the features is lacks. This answer provides an example for building yours though.

Display image with absolute path on Winows with PHP's built in server [duplicate]

I'm loading a html file hosted on the OS X built in Apache server, within that file I am linking to another html file in the same directory as follows:
<a href="2ndFile.html"><button type="submit">Local file</button>
This works. However (for reasons too lengthy to go into) I am experimenting using the file: scheme instead, however I cannot get anything to work. Here is how I am re-writing the above line using file:
<a href="file://192.168.1.57/~User/2ndFile.html"><button type="submit">Local file</button>
(192.168.1.57 is my current IP address)
Changing it to the following does also not work:
<a href="file://Name-Of-MacBookPro/~User/2ndFile.html"><button type="submit">Local file</button>
But the file cannot be found, how should it be specified using the file: scheme?
The file: URL scheme refers to a file on the client machine. There is no hostname in the file: scheme; you just provide the path of the file. So, the file on your local machine would be file:///~User/2ndFile.html. Notice the three slashes; the hostname part of the URL is empty, so the slash at the beginning of the path immediately follows the double slash at the beginning of the URL. You will also need to expand the user's path; ~ does no expand in a file: URL. So you would need file:///home/User/2ndFile.html (on most Unixes), file:///Users/User/2ndFile.html (on Mac OS X), or file:///C:/Users/User/2ndFile.html (on Windows).
Many browsers, for security reasons, do not allow linking from a file that is loaded from a server to a local file. So, you may not be able to do this from a page loaded via HTTP; you may only be able to link to file: URLs from other local pages.
the "file://" url protocol can only be used to locate files in the file system of the local machine. since this html code is interpreted by a browser, the "local machine" is the machine that is running the browser.
if you are getting file not found errors, i suspect it is because the file is not found. however, it could also be a security limitation of the browser. some browsers will not let you reference a filesystem file from a non-filesystem html page. you could try using the file path from the command line on the machine running the browser to confirm that this is a browser limitation and not a legitimate missing file.
The 'file' protocol is not a network protocol. Therefore file://192.168.1.57/~User/2ndFile.html simply does not make much sense.
Question is how you load the first file. Is that really done using a web server? Does not really sound like. If it is, then why not use the same protocol, most likely http? You cannot expect to simply switch the protocol and use two different protocols the same way...
I suspect the first file is not really loaded using an apache http server at all, but simply by opening the file? href="2ndFile.html" simply works because it uses a "relative url". This makes the browser use the same protocol and path as where he got the first (current) file from.
I had similar issue before and in my case the file was in another machine
so i have mapped network drive z to the folder location where my file is
then i created a context in tomcat
so in my web project i could access the HTML file via context
For apache look up SymLink or you can solve via the OS with Symbolic Links or on linux set up a library link/etc
My answer is one method specifically to windows 10.
So my method involves mapping a network drive to U:/ (e.g. I use G:/ for Google Drive)
open cmd and type hostname (example result: LAPTOP-G666P000, you could use your ip instead, but using a static hostname for identifying yourself makes more sense if your network stops)
Press Windows_key + E > right click 'This PC' > press N
(It's Map Network drive, NOT add a network location)
If you are right clicking the shortcut on the desktop you need to press N then enter
Fill out U: or G: or Z: or whatever you want
Example Address: \\LAPTOP-G666P000\c$\Users\username\
Then you can use <a href="file:///u:/2ndFile.html"><button type="submit">Local file</button> like in your question
related: You can also use this method for FTPs, and setup multiple drives for different relative paths on that same network.
related2: I have used http://localhost/c$ etc before on some WAMP/apache servers too before, you can use .htaccess for control/security but I recommend to not do so on a live/production machine -- or any other symlink documentroot example you can google

How do I get PHPStorm to use the correct path for CSS?

I have been using "Delphi PHP XE2". The file structure has worked fine for over a year on the development machine and the production.
The folders are organised as follows.
src/app_login.php
src/add
src/css
src/js
src/fnc
src/db
src/images
etc.
I am just trying out PHPSTORM. The include files work fine. When I run it in Firefox it can find all images, JavaScript files, etc. But it can not find the CSS files as it is looking for them in
css
rather than
src/css
I haven't changed anything.
Why is the browser now looking at absolute path rather than relative?
How did PHPStorm manage to tell it that?
And how do I coerce it to treat them as relative paths?
I see that in the browser it runs it as:
http://localhost:63342/SRC/app_login.php
instead of
http://localhost:63342/app_login.php
I guess this the problem. How do I coerce it to move down one directory level?
I am trying to set up IIS, I think this might be best for later on. Here are the screen shots:
I configured the hosts file so that when I type wys.com in the browser it tries to run it and shows a blank page. If I type in 192.168.1.0 it just shows a blank page. View Source shows nothing. I was expecting it to run the index.html at d:\wys\src. Why is the browser not running it?
You are using PhpStorm's own simple built-in web server which uses URLs like http://localhost:63342/ProjectName/app_login.php. You cannot make http://localhost:63342/app_login.php using such server as it will not be able to tell what files to serve.
Either use your own Apache/IIS/whatever web server .. or the best you can get with built-in server would be http://ProjectName:63342/app_login.php(IDE needs to know what site/files to serve somehow). For that:
Edit your hosts file (or local DNS server, if preferred and have one) and point ProjectName to your computer's IP (e.g. 127.0.0.1).
Create Deployment entry of correct type (In Place should do), configure it (provide desired URL etc -- http://ProjectName:63342/) and mark it as Default for this project -- now IDE will use URL from there when generating "open in browser" URLs.

Can we acces a file in C or D drive or any out side drive from a html/php program file in in wamp webserver(localhost server)?

I have a simple html program. It has a link, targeted to a pdf file.
Please see the program here
filename : invoice.html
My invoice
Here when I click on the link, pdf file will be open. Working well.
Then I called the same file from my localhost wamp server.
http://localhost/invoice.html.
But When I call the same program from my localhost, my link is not working!!!
Can you explain me why it is not working or how I can activate the link. Is there any option in Apache server or php settings ?
What's an "out side drive"?
I have a simple html program
HTML is not a programming language - its a data construct / declaration.
Here when I click on the link...Working well....http://localhost/invoice.html...not working
Does that mean that it works when you load the HTML file directly from your filesystem?
why it is not working or how I can activate the link
Certainly it has got nothing to do with Perl, PHP, Apache nor WAMP (the tags on your post). The problem is on your browser.
Is there any option in Apache server or php settings ?
No - because the problem is strictly client side.
I assume that the target file exists on the machine where you are running the browser.
It would have helped if you'd said which browsers you had tested this with. I would have expected it to have worked. Did you get an error message?
did you check if apache server is running on localhost? try to stop and restart the server and check if it works.
The link points to the C:\invoice.pdf on the client side. I wonder if this is what you want. It's more likely that you setup another Directory and alias in httpd.conf which points to C:\, then change the link accordingly.

Flashbanner on php website with actionscript

A while back I asked how to open a file in actionscript to supply information for my flash banner.
It works nicely when I just open the flash file on my computer, but when I upload it to my website it does not show the data from the remote text file...
I know that the file reading bit of the program is correct, as it reads local files on the same web server just fine. So I assume it has something to do with either PHP or the FlashPlayer.
Thanks for any help you can give me!
===
How stupid of me to forget to mention that the file being loaded is from a remote server.
Thus the path to it is an actual URL. As I said this works fine on the computer regardless of whether the file is local or a remote file.
But on the PHP webserver it only wants to read the local files, it doesn't Read the Remote ones...
===Update
I've tried the crossdomain.xml solution, but it seems not to be working.
The banner is located on the actual webserver (http://forum.mydomainhere.com/)
while the text file is located at:
http://files.mydomainhere.com/ - this is a DNS reference to my file server.
The xml file i created looks like:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="www.forum.mydomainhere.com/" />
</cross-domain-policy>
As it said I put it on the http://files.mydomainhere.com/ server.
==
EDIT
I changed the www. simply to a * which made it work. That's when I removed the www. bit and it still works like a charm. my quess is my forum doesn't work at www. but just a http://
Thanks for all the help people :)
You're probably having a path issue, meaning Flash can't find the specified file. Flash loads external files starting from its containing page location, eg: the PHP page that contains it, not where the SWF is located.
Further, path may be handled differently on the web server than on the local file system. If you are using relative paths, try adding "./" onto the path, or removing "./" if it is already there.
If you are using absolute paths, make sure the path is in the same domain as the SWF. If the browser is at http://www.mysite.com but Flash is loading the file from http://mysite.com (no www) it is actually in a different security domain, and outside of your sandbox. Make sure they are the same.
If you post some more details, we'll be better able to identify your problem.
I hope that helps,
Edit
Based on comment below, you need a cross domain file on the other server. Lots of info on the web about those, start here for a good guide: http://kb2.adobe.com/cps/142/tn_14213.html
SWF's have different security rules based on where you are running them, when you are debugging through one of the IDE's the security settings are very relaxed.

Categories