I'm trying to implement a script on an html template where after loading the template, the file download starts automatically. My files in question are txt, csv and xlsx.
After 2 seconds, as per setTimeout, the script is activated but it does not download the file, but opens a new page as the content of it.
Another question I wanted to ask was whether it is possible to put the absolute path of the file as the folder containing them is nested at a higher level than $ _SERVER ["DOCUMENT_ROOT"]
.
$file = '/var/www/.........../file.txt';
echo "<script>
\$(function() {
\$('a[data-auto-download]').each(function(){
var \$this = \$(this);
setTimeout(function() {
window.location.href = \$this.attr('href');
}, 2000);
});
});
</script>
<a data-auto-download href=\"".$file."\">here</a>";
Via Active questions tagged javascript - Stack Overflow https://ift.tt/yAMKqGJ
Comments
Post a Comment