i have created this piece of code to retrieve the path to a file from a mysql db, the file exists and can be displayed directly from the sql query. the code looks like this

$query = "SELECT broad1 FROM images_broad";
$result=mysql_query($query);

while($row=mysql_fetch_array($result)){
$image_path="{$row['broad1']}";
}

i now want to display this image inside an email. so the next part of the code use a variable to hold the first part of the path as only the relative path is stored in the db. they are the appended together to give the absolute path of the image to be displayed. the code looks like this

$path= 'http://www.acmeart.co.uk/mercury';
$broad_img1='<img src="' . $path."/".$image_path .'" />';

when the source code of the email is viewed on the $path is showing in the source, would the $image_path still hold a value inside.

all the code together looks like this

$query = "SELECT broad1 FROM images_broad";
$result=mysql_query($query);

while($row=mysql_fetch_array($result)){
$image_path="{$row['broad1']}";
}

$path= 'http://www.acmeart.co.uk/mercury';
$broad_img1='<img src="' . $path."/".$image_path .'" />';

to display the image inside the body of the email i have used this code

' . $broad_img1 .'

i know this works as i have had images showing up but had to change the code because of images being cached.

you can break caches by appending a ?[somevar]=[random string] after the image tag. They determine freshness by url (is it the same?) then, if the url is the same, by checking last modified date, E-Tag, etc.

You can also serve them up using php to load the image and pass it through, and adding some custom headers before sending the image and flushing the buffer:
Last-Modified: [current time/date] -for cache server
E-Tag: [random string] -for cache server
Expires: [yesterday] -for cache server
Cache-Control: must-revalidate, max-age=1 -for cache server
Pragma: no-cache, NoCache(for internet exploder) -for browser, most caches ignore this

caches are not all the same so it's good to hedge your bets 8)

These combined will probably break any cache unless the cache actually compares the files, which would be intense in a large ISP.

http://www.mnot.net/cache_docs/#PRAGMA
Is a tutorial that explains how to get all of your content cached. For spotlight images or banner serving you basically want to do the exact opposite of what this page tells you ROFL.

A more internet friendly way to accomplish is to go ahead and let the cache servers cache the images, since when an image is hit, and it's cached, a request still reaches the server, it'll show a 304 response for these and record the request URI so you can match on the image. The difference is usually less than 100 bytes are sent over the wire in such an exchange so it's a lot more efficient for your server. The connection time for the exchange is also cut. This means less memory and bandwidth get used for 304s.

If you are watching the log for the site you can get the data as sure as if serving it from a script, and make your scalability better.

I only know all of this because I wrote a 3rd party ad server once which audited doubleclick for our clients.

-r

Member Avatar for amigura

to see wat you get.

echo $path."/".$image_path;

thanks for the reply i ended up appeding a random number on the end of the file for display only. the code i used to accomplish this was something like this i will put the proper code up on monday.

$broad_img1='<img src="' . $path."/".$image_path."?".$rand .'" />';

as the number was not getting stored with the file anymore i just used if file exists function to retrieve the file before the random number was added.

it is all working. yay

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.