[英]Hyperlink multi-level sub-directories through index.php? structure
I'm trying to create a hyperlink structure that can access multi-level sub folders. 我正在尝试创建一个可以访问多级子文件夹的超链接结构。 For now, I can access my hyperlinks with only one-level (php) directory, such like
index.php?content=about
(whereas 'about' is about.php). 现在,我只能使用一级(php)目录访问我的超链接,例如
index.php?content=about
(而“ about”是about.php)。
What I want to do is to create a filing system for a larger website with multi-level sub-directories like the following example, index.php?blog/category/process/
. 我想要做的是为一个具有多级子目录的大型网站创建一个文件系统,如下面的示例
index.php?blog/category/process/
。 I don't know if there is a symbol that replaces html symbol / (slash for directory) but for PHP directories. 我不知道是否有代替HTML符号/(用于目录的斜杠)但用于PHP目录的符号。 I tried different ways of accessing files inside multi-level sub-directories, such as putting the ?
我尝试了多种方法来访问多级子目录中的文件,例如将? (question mark).
(问号)。 It was all hypothetically experimental.
假设所有这些都是实验性的。 If I use the slash, such in the form '
blog/category/process/filename.php
', I get a 404 Not Found error. 如果我使用斜杠(例如“
blog/category/process/filename.php
”的形式),则会收到404 Not Found错误。
There is the following PHP script inside function.php, that gets the content from the URL, if there is no content, it sets a default and if there is content, it sanitizes data against hacking: 在function.php中有以下PHP脚本,该脚本从URL获取内容,如果没有内容,则设置默认值,如果有内容,则清除数据以防止被黑客入侵:
function loadContent($where, $default='') {
$content = filter_input(INPUT_GET, $where, FILTER_SANITIZE_STRING);
$default = filter_var($default, FILTER_SANITIZE_STRING);
$content = (empty($content)) ? $default : $content;
if ($content) {
$html = include 'content/'.$content.'.php';
return $html;
}
}
function loadIncludes($where, $default='includes/') {
$includes = filter_input(INPUT_GET, $where, FILTER_SANITIZE_STRING);
$default = filter_var($default, FILTER_SANITIZE_STRING);
if($includes) {
$html = include 'includes/'.$includes.'.php';
return $html;
}
}
The link to the document inside 'blog/category/process/filename.php' shows up (where it was '404 Error' before, but the header and the css files do not work. They are not been picked up. 显示到'blog / category / process / filename.php'中文档的链接(之前为'404 Error',但标头和css文件不起作用。它们没有被拾取。
Please note: 请注意:
My website structure is 我的网站结构是
Header (one header picked up by index.php?) 标头(由index.php获取一个标头?)
Content (multiple content=filename.php) 内容(多个content = filename.php)
Footer 页脚
index.php looks like this: index.php看起来像这样:
<?php
require ('includes/function.php');
require ('includes/init.php'); /* init.php picks up the header */
?>
<div class="clearboth"></div>
<!-- ******** HOMEPAGE ********** -->
<?php loadContent('content', 'home'); ?>
<div class="clearboth"></div>
<!-- ******** FOOTER ********** -->
<?php include ('content/footer.php'); ?>
I found the solution on the structure of the multi-level sub-directories through index.php? 我通过index.php找到了有关多级子目录结构的解决方案? that also picks up the CSS, which is as follows:
还可以选择CSS,如下所示:
<a href="index.php?content=blog/category/process/filename">
(leave out the extension .php followed after 'filename')
Thank you for all your help! 谢谢你的帮助!
<?php
/* FOLDERS STRUCTURE
$_SERVER['DOCUMENT_ROOT'] = C:/Server/www/music; // YES Windows :)
THIS FILE = folders.php
C:/Server/www/music
C:/Server/www/music/files/
C:/Server/www/music/files/folder1/
C:/Server/www/music/files/folder1/folder2/myfile.jpeg
*/
$root = $_SERVER['DOCUMENT_ROOT'];
$requestURI = $_SERVER['REQUEST_URI'];
$startFolder = '/files/';
preg_match('/\?/', $requestURI) ? list($requestURI, $fileToFind) = explode('?', $_SERVER['REQUEST_URI']) : exit('Bad request');
$file = $root.$startFolder.$fileToFind;
if(file_exists($file)){
//YOUR CODE
}
else {
header("HTTP/1.0 404 Not Found");
}
// Usage = http://music.com/folders.php?/folder1/folder2/myfile.jpeg
?>
Read those questions I had asked before. 阅读我之前问过的那些问题。 I hope it will help you
希望对您有帮助
.htaccess : Redirect all http requests to one file whitout 404 resp.
.htaccess:将所有http请求重定向到一个文件,分别为404和404。 code
码
Note that you may play with http headers header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
请注意,您可能会使用http标
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
or header($_SERVER["SERVER_PROTOCOL"]." 200 Ok");
或
header($_SERVER["SERVER_PROTOCOL"]." 200 Ok");
In case the file exists or not 如果文件存在或不存在
Active your imagination... 发挥想象力...
I found the solution on the hyperlink structure of a multi-level sub-directories through index.php? 我通过index.php找到了多级子目录的超链接结构的解决方案? that also picks up the CSS, and does not issue a 404 Error, which is as follows:
也会拾取CSS,并且不会发出404错误,如下所示:
<a href="index.php?content=blog/category/process/filename">
descriptive header
</a>
(note: remember to leave out the extension .php followed after 'filename') (注意:切记不要在文件名后加上扩展名.php)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.