On 25 June 2010 21:02, Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:
>
> On Fri, 2010-06-25 at 21:01 +0200, Peter Lind wrote:
>
> On 25 June 2010 20:59, Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:
> >
> > On Fri, 2010-06-25 at 20:57 +0200, Peter Lind wrote:
> >
> > On 25 June 2010 19:35, Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:
> > > On Fri, 2010-06-25 at 19:31 +0200, Karl Cifius wrote:
> > >
> > >> Hi,
> > >>
> > >> I'm making a Facebook application that can generate images to user's
> > >> albums. To publish a story a thumbnail of this image is stored on my
> > >> server. Since this server currently is very limited I want to be able
> > >> to clean these thumbnails pretty often.
> > >>
> > >> To not get broken links in older facebook stories the address to the
> > >> thumbnail is a php script that checks if the thumbnail is available
> > >> and returns it, or otherwise returns a default thumbnail.
> > >>
> > >> I have solved this using the following code:
> > >>
> > >> $tImage = $_GET['i'];
> > >> $tURL   = "upload/$tImage.jpg";
> > >> if(!($fp=fopen($tURL,"rb"))){
> > >>    header("Location: thumb.jpg");
> > >> }else{
> > >>    header("Location: upload/$tImage.jpg");
> > >>    fclose($fp);
> > >> }
> > >>
> > >> My question is if it would be better to have a mysql database with
> > >> information about the thumbnail and check if the image is there,
> > >> instead of checking if the image file can be loaded? What is the most
> > >> optimized approach if I start to gain traffic?
> > >>
> > >>
> > >> Thanks,
> > >>
> > >> /Karl
> > >>
> > >
> > >
> > > I think checking for the existence of a file is probably going to be the
> > > quicker approach. Unless you have a server with loads of RAM and your DB
> > > is very small, it's unlikely your DB will exist entirely in memory, so
> > > you will at some point have to access the files that the DB uses, even
> > > though this is done by the server automatically.
> > >
> > > On another note, I would try to sanitise that $_GET variable a bit, as
> > > it could lead to issues down the line later. Maybe limit the string to
> > > patterns you expect for an image URL.
> > >
> > > Thanks,
> > > Ash
> > > http://www.ashleysheridan.co.uk
> > >
> >
> > Might be quicker to do with a .htaccess file - you can avoid loading php at 
> > all.
> >
> > Regards
> > Peter
> >
> >
> >
> > PHP can do things that .htaccess can't, like verify a specific ID has 
> > access to an image, etc.
> >
>
> I must've missed the part in the code where the ID was checked ...
> Nope, still can't find it.
>
> Regards
> Peter
>
>
> --
> <hype>
> WWW: http://plphp.dk / http://plind.dk
> LinkedIn: http://www.linkedin.com/in/plind
> BeWelcome/Couchsurfing: Fake51
> Twitter: http://twitter.com/kafe15
> </hype>
>
> It wasn't in the example, but generally I've found the only reason someone 
> ever thinks of doing something like this rather than directly link to the 
> image is for some sort of validation reason. I assumed it was a slimmed-down 
> code sample that only showed us what we needed.
>

Ahh, I see. I assumed the OP would have told us if that was the case -
I prefer answering the stated questions instead of guessing at what
they are.

Regards
Peter

--
<hype>
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
</hype>

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

Reply via email to