-1

Here is the code where I am using uniqid script

<a href="" id="download" download="<?php echo uniqid(mt_rand(), true)?>-meme.png" >Download</a>

and the Javascript code

$('#download').click(function() {
var data = canvas.toDataURL();
download.href = data;
});

Here is the demo page.

When I click on download link a random name is generated but when I click no it again without refreshing the page I get the same filename?

Chandru
  • 1,306
  • 13
  • 21
Nitish Kumar
  • 163
  • 1
  • 8
  • _“but when I click no it again without refreshing the page I get the same filename?”_ – of course you get the same filename – because the content of the `download` attribute of the link is still the same. How do you expect that to change, _without_ reloading the page? – CBroe Jan 24 '15 at 05:11
  • Is there anyway to generate unique name without reloading the page. – Nitish Kumar Jan 24 '15 at 05:13
  • 1
    http://stackoverflow.com/questions/4872380/uniqid-in-javascript-jquery – CBroe Jan 24 '15 at 05:13

1 Answers1

1

Your code runs only once, on the server where the HTML page is generated. To have the uniqid change each time the link is clicked, the randomizing code MUST run on the client side (which means Javascript).

Aaron D
  • 7,540
  • 3
  • 44
  • 48