I want to store frequently-used graphic elements in a db and serve
them from there rather than from the filesystem.
Is there a better/faster way to do that than this? (error checking
etc not shown)
The relevant piece of the page:
<?php
echo
'<table><tr><td>
<img src="ImageFromDB.php?Image=ImageIdentifer">
</td></tr></table>' ;
?>
ImageFromDB.php:
<?php
$imgname = $_GET['Image'] ;
$dset = mysql_query( 'SELECT imagebits FROM graphics_table
WHERE name="' . $imgname . '"' ) ;
$rec = mysql_fetch_row($dset) ;
$browser = fopen( 'php://output', 'w') ;
header( 'Content-Type: image/png' ) ;
fwrite( $browser, $rec[0] ) ;
?>
I fingered through the docs and did some googling, but didn't find
anything obviously helpful. Many thanks for any insights.
Margaret
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.) 13 1871
"Margaret MacDonald" wrote: I want to store frequently-used graphic elements in a db and serve them from there rather than from the filesystem.
Is there a better/faster way to do that than this? (error checking etc not shown)
The relevant piece of the page: <?php echo ’<table><tr><td> <img src="ImageFromDB.php?Image=ImageIdentifer"> </td></tr></table>’ ; ?>
ImageFromDB.php: <?php $imgname = $_GET[’Image’] ; $dset = mysql_query( ’SELECT imagebits FROM graphics_table WHERE name="’ . $imgname . ’"’ ) ; $rec = mysql_fetch_row($dset) ; $browser = fopen( ’php://output’, ’w’) ; header( ’Content-Type: image/png’ ) ; fwrite( $browser, $rec[0] ) ; ?>
I fingered through the docs and did some googling, but didn’t find anything obviously helpful. Many thanks for any insights.
Margaret
Margaret, your script and db are going thru a lot of processing just
to serve frequently used images. Why not save them on disk, and put
their path (or file name) in the db. Is there an important reason
to save them to db?
-- http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Serving-...ict139672.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=467181
steve wrote: "Margaret MacDonald" wrote: I want to store frequently-used graphic elements in a db and serve them from there rather than from the filesystem.
Is there a better/faster way to do that than this? (error checking etc not shown)
The relevant piece of the page: <?php echo ’<table><tr><td> <img src="ImageFromDB.php?Image=ImageIdentifer"> </td></tr></table>’ ; ?>
ImageFromDB.php: <?php $imgname = $_GET[’Image’] ; $dset = mysql_query( ’SELECT imagebits FROM graphics_table WHERE name="’ . $imgname . ’"’ ) ; $rec = mysql_fetch_row($dset) ; $browser = fopen( ’php://output’, ’w’) ; header( ’Content-Type: image/png’ ) ; fwrite( $browser, $rec[0] ) ; ?>
I fingered through the docs and did some googling, but didn’t find anything obviously helpful. Many thanks for any insights.
Margaret
Margaret, your script and db are going thru a lot of processing just to serve frequently used images. Why not save them on disk, and put their path (or file name) in the db. Is there an important reason to save them to db?
Mainly as a security thing, Steve. The people for whom I'm doing this
project expect relentless attacks to be made on their site (I suspect
that they're probably right) so my goal is to make the whole thing as
seamless and opaque as I possibly can.
Margaret
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)
I wrote: ... my goal is to make the whole thing as seamless and opaque as I possibly can.
That should have been 'as I possibly can consistent with usable
performance'.
Margaret
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)
"Margaret MacDonald" wrote: I wrote:... my goal is to make the whole thing as seamless and opaque as I possibly can.
That should have been ’as I possibly can consistent with usable performance’.
Margaret
Margaret, are you talking about stopping leeching, i.e. people linking
to these images. If that is the case, there are many other solutions.
Check for "anti-leeching" on search engines.
-- http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-Serving-...ict139672.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=467277
steve wrote: "Margaret MacDonald" wrote: I wrote:... my goal is to make the whole thing as seamless and opaque as I possibly can.
That should have been ’as I possibly can consistent with usable performance’.
Margaret
Margaret, are you talking about stopping leeching, i.e. people linking to these images. If that is the case, there are many other solutions. Check for "anti-leeching" on search engines.
No, actually I don't care about that, Steve--they can always grab the
image from the screen if that's what they want. My purpose is to
frustrate the ones who will be trying to collect information as a
prelude to and tool for breaking in. If they can't learn the
filesystem structure or filenames, it becomes that much harder for
them to attack the system.
Margaret
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)
On Sat, 14 Aug 2004 13:28:17 GMT, Margaret MacDonald
<sc**********@att.not.invalid> wrote: I want to store frequently-used graphic elements in a db and serve them from there rather than from the filesystem.
Is there a better/faster way to do that than this? (error checking etc not shown)
The relevant piece of the page: <?php echo '<table><tr><td> <img src="ImageFromDB.php?Image=ImageIdentifer"> </td></tr></table>' ; ?>
ImageFromDB.php: <?php $imgname = $_GET['Image'] ; $dset = mysql_query( 'SELECT imagebits FROM graphics_table WHERE name="' . $imgname . '"' ) ; $rec = mysql_fetch_row($dset) ; $browser = fopen( 'php://output', 'w') ; header( 'Content-Type: image/png' ) ; fwrite( $browser, $rec[0] ) ; ?>
I fingered through the docs and did some googling, but didn't find anything obviously helpful. Many thanks for any insights.
Looks OK to me. A plain 'print' would likely do just as well as opening the
output stream as you've done, but there's nothing wrong with that. You might
want to change the mode to 'wb' though to indicate binary mode.
If these images are frequently accessed then it might be worth considering
using a filesystem-based cache if the database queries take noticable amounts
of resources.
General opinion on this group is to not store images in a database and instead
just store a filesystem path. However, I believe that if the images are
(a) user data rather than static source code of the site
(b) have relationships with data in the database
(c) have any sort of value with regards to the end-user
... then it's worth considering storing them in full in the database so you
can include them consistently in the database backups, and have the same
transaction guarantees as all the other data on them.
--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
"Margaret MacDonald" wrote: steve wrote:
"Margaret MacDonald" wrote: I wrote: >... my goal is to make the whole thing as >seamless and opaque as I possibly can.
That should have been ’as I possibly can consistent with usable performance’.
Margaret
Margaret, are you talking about stopping leeching, i.e. people linkingto these images. If that is the case, there are many other solutions. Check for "anti-leeching" on search engines.
No, actually I don’t care about that, Steve--they can always grab the image from the screen if that’s what they want. My purpose is to frustrate the ones who will be trying to collect information as a prelude to and tool for breaking in. If they can’t learn the filesystem structure or filenames, it becomes that much harder for them to attack the system.
Margaret
oh, I see. Sorry if I have taken the thread off-track (?). In any
case, you can always mask the file system with php. No need to pull
from db, same effect. Ok, sorry again.
"Margaret MacDonald" <sc**********@att.not.invalid> wrote in message
news:uc********************************@4ax.com... steve wrote:
"Margaret MacDonald" wrote: I wrote: >... my goal is to make the whole thing as >seamless and opaque as I possibly can.
That should have been 'as I possibly can consistent with usable performance'.
Margaret
Margaret, are you talking about stopping leeching, i.e. people linking to these images. If that is the case, there are many other solutions. Check for "anti-leeching" on search engines.
No, actually I don't care about that, Steve--they can always grab the image from the screen if that's what they want. My purpose is to frustrate the ones who will be trying to collect information as a prelude to and tool for breaking in. If they can't learn the filesystem structure or filenames, it becomes that much harder for them to attack the system.
Apache rewrite is probably a better solution here.
steve wrote: Margaret, are you talking about stopping leeching, i.e. people linkingto these images. If that is the case, there are many other solutions. Check for "anti-leeching" on search engines.
No, actually I don’t care about that, Steve--they can always grab the image from the screen if that’s what they want. My purpose is to frustrate the ones who will be trying to collect information as a prelude to and tool for breaking in. If they can’t learn the filesystem structure or filenames, it becomes that much harder for them to attack the system.
Margaret
oh, I see. Sorry if I have taken the thread off-track (?). In any case, you can always mask the file system with php. No need to pull from db, same effect. Ok, sorry again.
No, actually I'm glad you brought up leeching, Steve, so: thanks! As
you can tell from my response to you, I misunderstood what you meant
(I hadn't heard the term 'leeching' in this context before). Yes, I
can now see that preventing leeching will be an issue as well. My
problem is that web development is a completely new thing for me--my
experience has all been with shrinkwrap and systems software--so there
are plenty factors that simply don't occur to me til someone else
brings them up--usually by accident :-)
Margaret
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)
Chung Leong wrote: "Margaret MacDonald" <sc**********@att.not.invalid> wrote in message news:uc********************************@4ax.com.. . steve wrote:
>"Margaret MacDonald" wrote: > > I wrote: > > >... my goal is to make the whole thing as > > >seamless and opaque as I possibly can. > > > > That should have been 'as I possibly can consistent with usable > > performance'. > > > > Margaret > >Margaret, are you talking about stopping leeching, i.e. people linking >to these images. If that is the case, there are many other solutions. > Check for "anti-leeching" on search engines.
No, actually I don't care about that, Steve--they can always grab the image from the screen if that's what they want. My purpose is to frustrate the ones who will be trying to collect information as a prelude to and tool for breaking in. If they can't learn the filesystem structure or filenames, it becomes that much harder for them to attack the system.
Apache rewrite is probably a better solution here.
I'll look into it, Chung. Thanks!
Margaret
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)
Andy Hassall wrote: On Sat, 14 Aug 2004 13:28:17 GMT, Margaret MacDonald <sc**********@att.not.invalid> wrote:
I want to store frequently-used graphic elements in a db and serve them from there rather than from the filesystem.
Is there a better/faster way to do that than this? (error checking etc not shown)
The relevant piece of the page: <?php echo '<table><tr><td> <img src="ImageFromDB.php?Image=ImageIdentifer"> </td></tr></table>' ; ?>
ImageFromDB.php: <?php $imgname = $_GET['Image'] ; $dset = mysql_query( 'SELECT imagebits FROM graphics_table WHERE name="' . $imgname . '"' ) ; $rec = mysql_fetch_row($dset) ; $browser = fopen( 'php://output', 'w') ; header( 'Content-Type: image/png' ) ; fwrite( $browser, $rec[0] ) ; ?>
I fingered through the docs and did some googling, but didn't find anything obviously helpful. Many thanks for any insights.
Looks OK to me. A plain 'print' would likely do just as well as opening the output stream as you've done, but there's nothing wrong with that. You might want to change the mode to 'wb' though to indicate binary mode.
If these images are frequently accessed then it might be worth considering using a filesystem-based cache if the database queries take noticable amounts of resources.
General opinion on this group is to not store images in a database and instead just store a filesystem path. However, I believe that if the images are
(a) user data rather than static source code of the site (b) have relationships with data in the database (c) have any sort of value with regards to the end-user
... then it's worth considering storing them in full in the database so you can include them consistently in the database backups, and have the same transaction guarantees as all the other data on them.
Thanks, Andy. I didn't even experiment with print() since I presumed
it would do gratuitous interpretation. And thanks for catching the
'b'--I seem to have a habit of missing that out.
Your articulation of when/why it can be good to store images in the db
fits for me.
Margaret
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)
On Sun, 15 Aug 2004 13:50:41 +0000, Margaret MacDonald wrote: oh, I see. Sorry if I have taken the thread off-track (?). In any case, you can always mask the file system with php. No need to pull from db, same effect. Ok, sorry again.
No, actually I'm glad you brought up leeching, Steve, so: thanks! As you can tell from my response to you, I misunderstood what you meant (I hadn't heard the term 'leeching' in this context before). Yes, I can now see that preventing leeching will be an issue as well. My problem is that web development is a completely new thing for me--my experience has all been with shrinkwrap and systems software--so there are plenty factors that simply don't occur to me til someone else brings them up--usually by accident :-)
<img src="/image.php/1" alt="Image 1" />
<?php
$images = array(
1 => '/full/path/to/image_1.png',
[ ... ]
);
$pi = explode('/', $_SERVER['PATH_INFO']);
if (file_exists($images[intavl($pi[1])])) {
header('Content-type: image/png');
readfile($images[intval($pi[1])]);
exit;
}
?>
Note, this is extremely simplified (and not optimised), but would disclose
no path to your users and still allow filesystem storage.
You could implement sessions or the likes to cut down maybe on hotlinking,
but outright preventing hotlinking is just a myth =)
HTH.
Regards,
Ian
--
Ian.H
digiServ Network
London, UK http://digiserv.net/
Margaret MacDonald wrote: Andy Hassall wrote:
On Sat, 14 Aug 2004 13:28:17 GMT, Margaret MacDonald <sc**********@att.not.invalid> wrote:
I want to store frequently-used graphic elements in a db and serve them from there rather than from the filesystem.
Is there a better/faster way to do that than this? (error checking etc not shown)
The relevant piece of the page: <?php echo '<table><tr><td> <img src="ImageFromDB.php?Image=ImageIdentifer"> </td></tr></table>' ; ?>
ImageFromDB.php: <?php $imgname = $_GET['Image'] ; $dset = mysql_query( 'SELECT imagebits FROM graphics_table WHERE name="' . $imgname . '"' ) ; $rec = mysql_fetch_row($dset) ; $browser = fopen( 'php://output', 'w') ; header( 'Content-Type: image/png' ) ; fwrite( $browser, $rec[0] ) ; ?>
I fingered through the docs and did some googling, but didn't find anything obviously helpful. Many thanks for any insights.
Looks OK to me. A plain 'print' would likely do just as well as opening the output stream as you've done, but there's nothing wrong with that. You might want to change the mode to 'wb' though to indicate binary mode.
If these images are frequently accessed then it might be worth considering using a filesystem-based cache if the database queries take noticable amounts of resources.
General opinion on this group is to not store images in a database and instead just store a filesystem path. However, I believe that if the images are
(a) user data rather than static source code of the site (b) have relationships with data in the database (c) have any sort of value with regards to the end-user
... then it's worth considering storing them in full in the database so you can include them consistently in the database backups, and have the same transaction guarantees as all the other data on them.
Thanks, Andy. I didn't even experiment with print() since I presumed it would do gratuitous interpretation. And thanks for catching the 'b'--I seem to have a habit of missing that out.
Your articulation of when/why it can be good to store images in the db fits for me.
Margaret
The only real downside on storing images s a database is if you're using
a system-based backup procidure. Then, every time oyu change an image,
then the whole data file needs to be saved again, and images tend not to
be small.
So why not apply the same logic above to the file name, and then store
the images somewhere else. That way they can be backed up individually
when they change, not en masse.
$0.02
Steve This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: -[ CaMeL ]- a55m0nk |
last post by:
Hi there
i am creating a clan website in ASP and am making a page serving
script
a link sends a query to the default page and then serves the page by
grabbing the HTML from a database that...
|
by: David W. Fenton |
last post by:
I have an app for a client (Access97, all the final service releases
and Jet service packs, full installation (not runtime)), that
displays a graphic in an image control based on a path/filename...
|
by: Martin |
last post by:
I am using graphics as backgrounds for forms,buttons,labels etc.
The question is: is it faster to load all graphics from files on app start
or
to use it embeded (places in editor during design)....
|
by: Peter Morris [Droopy eyes software] |
last post by:
Hi all
Instead of a url like so
http://www.howtodothings.com/viewarticle.aspx?id=1
I'd like to do this
http://www.howtodothings.com/articles/computers/dotnet/aspdotnet/001.html
|
by: Al |
last post by:
Hi,
I am trying to Save a RTF that contains graphics to SQL
server. Doesn't anyone know a VB code to do that?
Thanks
Al
|
by: SStory |
last post by:
I need to be able to give the appearance of glass over a picture inside of a
frame.
How can I do this in real time given that the picture will change?
Is there a way using the graphics to make...
|
by: Carlos Ojea Castro |
last post by:
Hello:
I want to display graphics from my postgresql database, but I must
choose the proper tool first.
Which one is more suitable?:
perl?
php?
pg_autodoc?
another one?
|
by: Csaba Gabor |
last post by:
Not sure of best place for this question...
Are there any built in images within the browser that I can assume
(particularly IE and FF)?
More specifically, I am writing a one file webApp.php...
|
by: Siv |
last post by:
Hi,
A little while ago I wrote a small program that allowed the user to view
products from a database. The database holds the details of the products
which can be viewed via a form and...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |