【发布时间】:2017-05-03 19:40:11
【问题描述】:
所以这就是我想要做的:
我试图能够从我想在 php 文件中回显它们的 php 文件中获取 CSS、JS 和 HTML 文件,并将文件中的类型设置为所需的类型 ex: if it is a js file set类型为text/javascript 如果它是css 将类型设置为text/css 我说doc type btw 页面类型,标题类型。我不知道它叫什么,但我希望浏览器将它解释为文件类型,即使它在技术上是 html。
我输入了一些代码..
<?php
if (isset($_GET['name'])) {
if (isset($_GET['type'])) {
if ($_GET['type'] === 'javascript') {
header('Content-type: text/javascript; charset: UTF-8');
$file = $_GET['name'].'.js';
$execjs = file_get_contents($file);
}
} elseif ($_GET['type'] === 'css') {
header('Content-type: text/css; charset: UTF-8');
$file = $_GET['name'].'.css';
$execcss = file_get_contents($file);
}
} if ($execjs === 'false') {
echo 'js 404';
} elseif ($execcss === 'false') {
echo 'css404';
}
?>
但这不适用于我选择的两种文件类型,它使用$_GET['name'] (Name in the query string) 和$_GET['type'] (type in the query string) 来获取文件名和文件类型,我还想让它通用,这样它几乎可以读取任何文件类型, 前任
js, css, php, html, xml, png, ico, jpg
我知道这可能很难做到,我只需要一些启动代码来让我继续构建文件
【问题讨论】:
-
您应该按照here 的描述使用 finfo_file。
标签: javascript php html css get