I am displaying file names as links on the page, when I click on particular link, it should ask the user that, save file or view file something like below image. enter image description here

In my case this popup is not coming, directly the file content is displaying on browser. So how can I achieve this. Thanks for your any suggestions.

My code to display dynamic links as follow:

$uri = 'public://'; 
  $path= file_create_url($uri);

$data .= '<div class = "public-file-names"><a href="'.$path . $foldnames .'/'. $filenames.'">' ."--". $filenames .'</a><br></div>';

1 Answer 1


The browser you are using recognise the linked document format and try to show it directly. It is mainly true with images and PDF files.

If you want to force the browser to download the file (or to open it with a local application), as explain in this answer, you can use the HTML5 download attribute.

$uri = 'public://'; 
$path= file_create_url($uri);

$data .= '<div class = "public-file-names"><a href="'.$path . $foldnames .'/'. $filenames.'" download>' ."--". $filenames .'</a><br></div>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.