Re: [yad] Re: php code to allowing image downloads from a yad --html --browser --uri from an iframe too

46 views
Skip to first unread message
Message has been deleted
Message has been deleted

Stephan Schutter

unread,
Jul 21, 2025, 12:02:51 PMJul 21
to yad-c...@googlegroups.com
Hi Robert, your command renders this for me: 
image.png

On Fri, Jul 4, 2025 at 5:56 PM 'Robert Cooper' via yad-common <yad-c...@googlegroups.com> wrote:
Corrected link to Code - Click Image Downloads that image:


On Thursday, July 3, 2025 at 11:07:27 PM UTC-5 Robert Cooper wrote:
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)



yad --html --browser title="yad html" --uri="https://me2pc.com/testing/click-download/commands.php" --width=1000 --height=500 --button="Exit Yad Browser:1"

yad-browser.png


clickable-php-in-iframe.png
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===================

--
You received this message because you are subscribed to the Google Groups "yad-common" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yad-common+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/yad-common/3773fc5f-ac5a-411a-b840-97c80e7b27c4n%40googlegroups.com.
Message has been deleted

Robert Cooper

unread,
Jul 21, 2025, 4:07:01 PMJul 21
to yad-common
I am no longer using yad for most of my projects once I learned that I create JavaScript frontend user interfaces that will run on both local and online which is not possible using yad. 

Here is the JavaScrit UI with api: that would never be possible with yad https://me2pc.com/me2pc_ui/

Here is a Drag & Drop for bash coding that I build last moth that I previously built with yad:  https://me2pc.com/html-terminal/me2pc-html-browser-terminal.html

Here is another example of using JavaScript that I could do with yad but, this will work online and locally as well too and it was actually easier to code with JavaScript. 

Even a more important reason to using Javascript is that AI LLM code generators are fully usable with JavaScript but, not for yad. 


Robert Cooper

unread,
Jul 22, 2025, 11:24:47 AMJul 22
to yad-common
Reply all
Reply to author
Forward
0 new messages