Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have two ways to do that:</p> <p>METHOD 1. The secure way. </p> <p>Put the images on /www/htdocs/</p> <pre><code>&lt;?php $www_root = 'http://localhost/images'; $dir = '/var/www/images'; $file_display = array('jpg', 'jpeg', 'png', 'gif'); if ( file_exists( $dir ) == false ) { echo 'Directory \'', $dir, '\' not found!'; } else { $dir_contents = scandir( $dir ); foreach ( $dir_contents as $file ) { $file_type = strtolower( end( explode('.', $file ) ) ); if ( ($file !== '.') &amp;&amp; ($file !== '..') &amp;&amp; (in_array( $file_type, $file_display)) ) { echo '&lt;img src="', $www_root, '/', $file, '" alt="', $file, '"/&gt;'; break; } } } ?&gt; </code></pre> <p>METHOD 2. Unsecure but more flexible. </p> <p>Put the images on any directory (apache must have permission to read the file).</p> <pre><code>&lt;?php $dir = '/home/user/Pictures'; $file_display = array('jpg', 'jpeg', 'png', 'gif'); if ( file_exists( $dir ) == false ) { echo 'Directory \'', $dir, '\' not found!'; } else { $dir_contents = scandir( $dir ); foreach ( $dir_contents as $file ) { $file_type = strtolower( end( explode('.', $file ) ) ); if ( ($file !== '.') &amp;&amp; ($file !== '..') &amp;&amp; (in_array( $file_type, $file_display)) ) { echo '&lt;img src="file_viewer.php?file=', base64_encode($dir . '/' . $file), '" alt="', $file, '"/&gt;'; break; } } } ?&gt; </code></pre> <p>And create another script to read the image file.</p> <pre><code>&lt;?php $filename = base64_decode($_GET['file']); // Check the folder location to avoid exploit if (dirname($filename) == '/home/user/Pictures') echo file_get_contents($filename); ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload