Re: New image already cached.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



$image_file = 'foo.jpg';
$random = mt_rand(1, 2000000000);
$url = "http://example.com/program/$random/$image_file";;
echo "<img src=\"$url\">

In program, if you echo out $_SERVER['PATHINFO'] you will see:
/454398574395/foo.jpg

The number will change, of course.

You can tear that apart and get the foo.jpg part to do whatever you want.

Or, you could have the URL sometimes have 'copyright' in it, and
sometimes not, and merge only when the URL has copyright in it.

You could even pass is paraeters like this:
http://example.com/program/width=200/2343242343/foo.jpg

Take the width=200 and scale the image to be 200 pixels wide.

Here is a real live example where I do this:
http://uncommonground.com/artist_profile/Ellen+Rosner

Right-click on that image of Ellen in the chair and check out that URL.

thumbnail is my PHP script.
target is a max width/height (I scale it proporationally and 200 is
max for both)
credits is the photographer credits from my database.
The rest is the URL of the actual real image I'm dinking with.

Feel free to play with the URL and change the 200 to, say, 100, or
make believe YOU took that photograph.

All just from the URL which, as far as the browser can tell, is a
perfectly valid set of directory paths on my machine, so the browser
can't possibly screw up.  (Rule #1: Never trust the browser.)

And in the main link, artist_profile is the PHP script, and if you
look at the links to the other artists at the bottom of the page,
you'll see that it also uses PATH_INFO to either show an artist by ID
or to search for their name in our database.

If multiple matches are found, the user is asked which one they meant:
http://uncommonground.com/artist_profile/Ellen

If I have the ID, then I know exactly which one to display.

I actually would suggest you go with:

/width=200/ though, instead of /width/200/ as it's easier to code and
have optional parameters using = and / as an arg separator.

I haven't bothered to fix that old script, but that's how I do it
nowadays.

On Wed, April 19, 2006 8:19 am, tedd wrote:
>>You're also better off embedding the parameters in the URL so that it
>>"looks like" a directory to the browser:
>>
>>http://example.com/actual_script/57823642346963/copyright/whatever.png
>>
>>The PHP scritp is actual_script.
>>
>>You can use .htaccess and ForceType to make Apache run it.
>>
>>$_SERVER['PATH_INFO'] will have all the parameters you need.
>>
>>The embedded parameters pretty much give the browser NO opportunity
>> to
>>screw up.
>
>
>
> Richard:
>
> Far out ! -- I never saw .htaccess and ForceType used before. But it
> works slick in dropping the extension of "program.php" to "program".
> (Now if I can only get my editor to still treat the document as php,
> but that's a different matter).
>
> However, I don't see how I can generate a random number for a url
> each time an image is needed and have .htaccess and ForceType make
> Apache run it -- do I rewrite. htaccess each time, or what?
>
> Also, $_SERVER['PATH_INFO'] (or in my case
> $_SERVER['PATH_TRANSLATED'] ) gives me the path -- so how does that
> fit in?
>
> Please explain.
>
> Thanks.
>
> tedd
>
> --
> --------------------------------------------------------------------------------
> http://sperling.com
>


-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux