将javascript文件转换为html实体

时间:2011-03-30 21:20:54

标签: php javascript html-entities

是否可以将* .js文件转换为html实体?

我使用此代码转换html文件,但javascript文件将无法正常工作。有可能吗?

$ch = curl_init($file_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$code = curl_exec($ch);
echo '<pre>'.htmlentities($code).'</pre>';

用户将文件上传到我的服务器,我不希望用户能够从我的服务器运行脚本。它应该只是文字。 禁止js文件不是一种选择。

1 个答案:

答案 0 :(得分:0)

HY

您可以检查上传文件是否具有.js扩展名并应用“htmlentities()”函数。 然后,如果必须下载文件,当用户下载文件时,检查其扩展名,如果是“.js”,则应用html_entity_decode()。

或者,您可以在用于上传的文件夹中添加.htaccess文件,并阻止对“.js”文件的外部访问:

<files *.js>

order allow,deny

deny from all

</files>