943,816 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 695
  • PHP RSS
May 15th, 2008
0

variable values

Expand Post »
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

PHP Syntax (Toggle Plain Text)
  1. $query = "SELECT broad1 FROM images_broad";
  2. $result=mysql_query($query);
  3.  
  4. while($row=mysql_fetch_array($result)){
  5. $image_path="{$row['broad1']}";
  6. }

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

PHP Syntax (Toggle Plain Text)
  1. $path= 'http://www.acmeart.co.uk/mercury';
  2. $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.
Similar Threads
Reputation Points: 27
Solved Threads: 1
Posting Whiz
kevin wood is offline Offline
347 posts
since Feb 2008
May 15th, 2008
0

Re: variable values

all the code together looks like this

PHP Syntax (Toggle Plain Text)
  1. $query = "SELECT broad1 FROM images_broad";
  2. $result=mysql_query($query);
  3.  
  4. while($row=mysql_fetch_array($result)){
  5. $image_path="{$row['broad1']}";
  6. }
  7.  
  8. $path= 'http://www.acmeart.co.uk/mercury';
  9. $broad_img1='<img src="' . $path."/".$image_path .'" />';

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

PHP Syntax (Toggle Plain Text)
  1. ' . $broad_img1 .'

i know this works as i have had images showing up but had to change the code because of images being cached.
Reputation Points: 27
Solved Threads: 1
Posting Whiz
kevin wood is offline Offline
347 posts
since Feb 2008
May 15th, 2008
0

Re: variable values

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
Last edited by rgviza; May 15th, 2008 at 2:13 pm.
Reputation Points: 18
Solved Threads: 5
Light Poster
rgviza is offline Offline
31 posts
since May 2008
May 15th, 2008
0

Re: variable values

to see wat you get.

PHP Syntax (Toggle Plain Text)
  1. echo $path."/".$image_path;
Reputation Points: 11
Solved Threads: 7
Junior Poster in Training
amigura is offline Offline
71 posts
since Jan 2008
May 16th, 2008
0

Re: variable values

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.

PHP Syntax (Toggle Plain Text)
  1. $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
Reputation Points: 27
Solved Threads: 1
Posting Whiz
kevin wood is offline Offline
347 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: php login page problem
Next Thread in PHP Forum Timeline: error checking for radio button and check boxes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC