Note: This php code works for images. What I need to download a text files that linked to the image in the same manner as I have done for images.
The trick to download files using the yad --html --browser --uri dialog is to code the download process in php. and make it automatic which bypasses the browser control.
This example is a 2 file process. (download source & image link below)
Down code & images here:
files: commands.php commands-downloads.php
========= BEGIN 1st file: commands.php===================
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>me2pc Commands</title>
<style>
.clickable-box:active {
/* Apply styles that create a momentary click effect */
transform: scale(2.60); /* Example: Shrink slightly */
background-color: #eee; /* Example: Change background color */
}
</style>
<style type="text/css">
.img-box{
display: inline-block;
text-align: center;
margin: 0 15px;
}
</style>
</head>
<body>
<center>
<font face="arial" size="6"><b>Clicking image will auto download it !!!!</b></font>
<table width=100% align=center padding="5">
<tr align=center valign=middle>
<td with=100% align=center valign=middle>
<p></p>
<p></p>
<p></p>
<?php
// Array containing sample image file names
$images = array("me2pc_sudo.png", "me2pc_apt-get-update.png", "me2pc_apt-get-upgrade.png", "me2pc_gparted.png", "me2pc_chromium.png", "me2pc_brave-browser.png", "me2pc_firefox.png", "me2pc_elgg-globe.png");
// Loop through array to create image gallery
foreach($images as $image){
echo '<div class="img-box"><div class="clickable-box"> ';
echo '<a href="commands-download.php?file=' . urlencode($image) . '">';
echo '<img src="images/' . $image . '" width="125" height=160 alt="' . pathinfo($image, PATHINFO_FILENAME) .'">';
echo '</a>';
echo '</div></div>';
}
?>
</td>
</tr>
</table>
</center>
</body>
</html>
========= END commands.php===================
========= BEGIN commands-download.php===================
<?php
if(isset($_REQUEST["file"])){
// Get parameters
$file = urldecode($_REQUEST["file"]); // Decode URL-encoded string
/* Test whether the file name contains illegal characters
such as "../" using the regular expression */
if(preg_match('/^[^.][-a-z0-9_.]+[a-z]$/i', $file)){
$filepath = "images/" . $file;
// Process download
if(file_exists($filepath)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($filepath).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filepath));
flush(); // Flush system output buffer
readfile($filepath);
die();
} else {
http_response_code(404);
die();
}
} else {
die("Invalid file name!");
}
}
?>
========= END commands-download.php===================