How to show popup for save or view the file?
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 .= '&lt;div class = "public-file-names"&gt;&lt;a href="'.$path . $foldnames .'/'. $filenames.'" download&gt;' ."--". $filenames .'&lt;/a&gt;&lt;br&gt;&lt;/div&gt;';