0

When i download a data uri(this works in chrome/FF),using

url1 = "data:attachment/plain;base64,encodeuri(<base64data-xyz>)"

Here using attachment mime type forces it to download, using any other mime type like(text/html) will open the content of file in new tab, since i wanted to download ,i used attachment/plain-xyz [MIME type].

I tried the download attribute, but everytime,the file name downloaded is "download", and there is no extension, so it gets appeneded in my downloads folder as ".FILE", whereas i need to store it using "variable.txt"

Please do guide me how you are able to change "download.FILE" to some "variable.txt", i have tried all attributes of data, download, data-downloadurl, contentdisposition,even tried setting pom attributes etc..

Please help in converting the downloaded file content to a file with some filename and .txt as extension

Pavan Kate
  • 84
  • 1
  • 8

2 Answers2

1

FileSaver.js provides easy ways to handle these

AnkitG
  • 6,438
  • 7
  • 44
  • 72
0
// Sanitizing the filename:
$filename = preg_replace('/[^a-z0-9\-\_\.]/i','',$_POST['filename']);

// Outputting headers:
header("Cache-Control: ");
header("Content-type: text/plain");
header('Content-Disposition: attachment; filename="'.$filename.'"');

or thisk link may be helpful [http://www.jtricks.com/bits/content_disposition.html][1]

user3722785
  • 216
  • 1
  • 13