I have my images on a external hardrive connected to my mac. This code works as expected to show a image.

<img src="<?php echo get_path.php;?>?id=<?php echo $row['id'];?>">

Content of get_path.php below.

$id = $_GET["id"];
$result = mysql_query("SELECT path FROM images WHERE id = '$id'");
$row = mysql_fetch_array($result);
header('Content-type: image/jpeg');
readfile($row['path']);

Now to my question. I want to use the same image in this javascript code.

document.getElementById("image_holder").innerHTML="<img src="image.png"/>";

How to use the php readfile in javascript?

    Not sure I understand your question. Seems like you simply need to point the 'src' attribute of the <img> element to your get_path.php script along with the appropriate 'id' value.

      I just come up with a solution. It seems so easy now :-)

      document.getElementById("image_holder").innerHTML="<img src='get_path.php?id=168'>";

        11 days later

        A JavaScript equivalent of PHP&#8217;s readfile
        ilesystem/readfile.js
        function readfile (filename, use_include_path, context) {
        var read_data = this.file_get_contents(filename, use_include_path, context); // bitwise-or use_include_path?
        this.echo(read_data);
        return read_data;
        }

          Write a Reply...