jim
jim

Reputation: 103

Help with windows path - PHP

I have this path and it is correct however, the browser will not include the source file unless I put "file:///" in front of it. I'm still developing and this will ultimately be on a Linux machine but in the mean time, I'd like to see my work as well as be able to troubleshoot it. Is there a solution for this?

This fails:

C:\Program Files (x86)\work\site\js\rowlock.js

This does not fail:

file:///C:\Program Files (x86)\work\site\js\rowlock.js

Upvotes: 10

Views: 29740

Answers (4)

Silver Light
Silver Light

Reputation: 45982

Try using variable $_SERVER['DOCUMENT_ROOT'] to make your script independent. For example:

include($_SERVER['DOCUMENT_ROOT'].'/js/rowlock.js');

Works fine on any system

Upvotes: 13

streetparade
streetparade

Reputation: 32918

Where is Your root folder?

If its C:\Program Files (x86)\work\site\

Then simple access your file like this

js/rowlock.js

This assuming that js is in the Root folder

Upvotes: 1

Andy
Andy

Reputation: 50640

Put quotes around your path. You have spaces, so it is not read correctly.

'C:\Program Files (x86)\work\site\js\rowlock.js'

Upvotes: 1

bcosca
bcosca

Reputation: 17555

just use front slashes everywhere if you'll be moving this to a linux box anyway. php for windows can understand it.

$file='c:/Program Files (x86)/work/site/js/rowlock.js';

Upvotes: 10

Related Questions