문제

I read up on how to define a rootpath constant that is useable in all subpages when using a single page application.

Now my question is, how can i use the basepath in my scripts i point to in my form actions?

My problem is that i want to use a relative path, compared to where the script is located, in the "action" scripts so that the path will work no matter from where that file is called.

I tried using

dirname(__FILE__) 

but as i use files in parent directories some levels up i ended up with something like

dirname(dirname((__FILE__))

and sometimes even another level up and i did not like the look of that.

After trying to to use a basepath constant i found out that it is not accessable in the scripts my forms are calling on form submit.

So my question is. How can i use a common basepath that works in the entire application? I was thinking about storing it in a session, but that seemed like a bad idea as it has no real place there.

Any advice would be appreciated, thanks in advance.

도움이 되었습니까?

해결책

There is no common basepath for both the client- and the server-side of your application.

On the client side, all paths are relative to the current url or absolute which is relative to the base url / domain name.

On the server side your are dealing with the file-system.

So if your site root on the server-side ($_SERVER["DOCUMENT_ROOT"]) is something like /home/some-user/www and your form processor is located at /home/some-user/www/assets/inc/process-form-1.php, that is the exact path you need on the server-side (if you want to use absolute paths...).

However, on the client-side, your action would point to a relative path or an absolute path which in this case would be /assets/inc/process-form-1.php; an absolute path relative to the root of the web-server.

다른 팁

The most usual solution is

dirname(dirname(__FILE__))

It is the most reliable solution, dont forget you can always go backwards as well

dirname(dirname(__FILE__)).'/../'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top