php - get image contain not download again -


Using the III framework. I have created a function / controller, which checks the image file, is present in the directory, if the file is using the file_gate_contents () function, then pass the image and set the background of the div tag. If the file does not exist, the default image file is passing.

syntax php: -

  header ('content-type: image / png'); Echo file_get_contents ($ location);  

And in Javascript I create a function to attract ADV and set the background of that div syntax: -

  function drawDiv () { $ ('. DivID'). HTML ("& lt; div id =" test "> 
" $$ ('# test'). CSS ({background-image: url ('http: // location / test / Getimage ')}}}

Whenever I redesign the division again, the image is downloaded every time. If I download url absolute path once.

What do I need if the image is present or does not exist then should download one time plz problem. If you have another solution tell me.

< P>

I use From a quick test, the image is not redownloaded. (See Scrabble Egbra below, or open your Network Panel and Test)

Implementation

Therefore, you can enter #test Set up (image with background, and styling you want), but hidden and whenever you want clone () .

  & Lt; div id = "test" style = "background-image: url (http: // location / test / getimage); display: none;" & gt; & gt; / div & gt;  < / Pre> 

and your javascript will be

  $ (" # testing"). Clone () Show (). Prepaido ("body");  

  • Note that the image is downloaded only once (open your network panel, and see)

code test

  $ ("img") .clone (). PrependTo ("body");  
  & lt; Script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min .js" & gt; & Lt; / Script & gt; & Lt; Img src = "https://www.google.co.uk/images/srpr/logo11w.png" />  

Image details here Enter


Comments

Popular posts from this blog

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

class - Kivy: how to instantiate a dynamic classes in python -

java - Algorithm negotiation fail SSH in Jenkins -