Is it possible to convert a *.js file to html entities?
I use this code to convert html files but javascript files won't work. 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.
Hy
You can check if the upload file has the .js extension and apply the "htmlentities()" function. Then, if the files must be downloaded, when the user download the file, check its extension, if its ".js", apply the html_entity_decode().
Or, you can add a .htaccess file in the folder used for upload, and block external access to ".js" files:
<files *.js>
order allow,deny
deny from all
</files>
精彩评论