Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two options for this, you could use the data protocol, which would embed the whole image into the URL of the background ( this isn't recommended if the image is bigger than a few kb. ) or you can use a script to present the image by encoding or recording a unique key for the image, eg bg.php?id=4323-34442-3432-4532 which checks a db for the id to retrieve the file path then echoes the content with the right content type.</p> <p>Some examples;</p> <p>based on the <a href="http://en.wikipedia.org/wiki/Data_URI_scheme#Inclusion_in_HTML_or_CSS_using_PHP" rel="nofollow">Data URI</a> wikipedia page</p> <h2>Data URI Method</h2> <p>Assuming a function like this;</p> <pre><code> function data_uri($fileID) { $fRecord = mysql_fetch_array( mysql_select("SELECT filePath, mimeType from fileTable WHERE fileID = " $fileID . ";") ); $contents = file_get_contents($fRecord['filePath']); $base64 = base64_encode($contents); return "data:$fRecord['mimeType'];base64,$base64"; } </code></pre> <p>Then in your html/php page you'd have the following snippet</p> <pre><code>style="background-image:url('&lt;?php echo data_uri($fileID);?&gt;' </code></pre> <h2>PHP Image Dump</h2> <p>Assuming a function like this;</p> <pre><code>// Given a filename and a mimetype; dump the contents to the screen function showDocumentContent($fileID){ $fRecord = mysql_fetch_array( mysql_select("SELECT filePath, mimeType from fileTable WHERE fileID = " $fileID . ";") ); header( 'Content-Encoding: none', true ); header( 'Content-Type: ' . $fRecord['mimeType'], true ); echo readfile( $fRecord['filePath'] ); } </code></pre> <p>Then in your html page you'd have this;</p> <pre><code>style="background-image:url('image.php?fileID=123') </code></pre> <p>In the first case, images larger than a few KB will result in equally large HTML pages, and may not be supported in browsers consistently. In the second case, you'd effectively have created a php script that is pretending to be an image. In both cases, the real path to the binary files on your server is abstracted away by storing a mapping in a database.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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