简体   繁体   English

将javascript文件转换为html实体

[英]convert javascript file to html entities

Is it possible to convert a *.js file to html entities? 是否可以将* .js文件转换为html实体?

I use this code to convert html files but javascript files won't work. 我使用此代码转换html文件,但javascript文件无法正常工作。 Is it possible? 可能吗?

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

The users upload files to my server and I don't want users to be able to run the script from my server. 用户将文件上传到我的服务器,但我不希望用户能够从我的服务器运行脚本。 It should be just text. 它应该只是文本。 Disallow js files is not an option. 不允许使用js文件。

Hy 海兰

You can check if the upload file has the .js extension and apply the "htmlentities()" function. 您可以检查上传文件是否具有.js扩展名,并应用“ htmlentities()”函数。 Then, if the files must be downloaded, when the user download the file, check its extension, if its ".js", apply the html_entity_decode(). 然后,如果必须下载文件,则在用户下载文件时,检查其扩展名(如果其为“ .js”),则应用html_entity_decode()。

Or, you can add a .htaccess file in the folder used for upload, and block external access to ".js" files: 或者,您可以在用于上传的文件夹中添加.htaccess文件,并阻止外部访问“ .js”文件:

<files *.js>

order allow,deny

deny from all

</files>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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