简体   繁体   中英

How can I access files outside webroot within an HTML tag?

I am on a shared host and do not have access to the php.ini or apache config files. I have PHP class files stored outside webroot that I need to access with HTML and I know that

<form action="../../classes/someclass.php" method="post">

will not work.

What kind of PHP script would I have to write to be able to access these files?

You would need to write a controller or proxy that's accessible and will route the request down to the desired class.

/someclassproxy.php

Inside that script you would have:

require '../../classes/someclass.php';

However, it's not common practice to have internal classes handle requests directly. Rather, the controller should use the class to handle the request.

You can't POST to nested files, but you can access files within your designated shared directory.

So suppose you have access to home/var/www/ or something like that. and have NO access above www.

You might have your site within a directory on that level, so your site would be at

home/var/www/yoursite

Now, suppose you had a file called config.php in the www folder. Suppose you ALSO have a file called post.php in the yoursite folder.

post.php can easily include config.php:

<?php 
include('../config.php');

?>

but obviously you cannot post to config.php because it is above the site's designated directory.

HOWEVER -

I don't think this is news to you. I'm not sure I understand your problem 100% since you seem to know enough to know you can access files with include...

Maybe I just don't get your question. Feel free to clarify any more than you think you already have. Or at least explain why you can't use a basic include

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM