By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,337 Members | 2,234 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,337 IT Pros & Developers. It's quick & easy.

Displaying 'image deleted' image if an image was deleted.

Markus
Expert 5K+
P: 6,050
Haha. The title makes me chuckle..

Anyway..

I've seen on numerous, large image hosting websites an image be displayed if the image, say, 'broke the TOS' or the image was deleted or the image can not be found.

I was just wondering how they went about this..
because i find it strange how they can replace an image, that's hosted on their server but embeded on a different website - If you understand me?

Thanks for your time and merry christmas :)

markus
Dec 22 '07 #1
Share this Question
Share on Google+
6 Replies


pbmods
Expert 5K+
P: 5,821
Heya, Markus.

So you're saying that you want to link to an image on a different server, but if the image meets certain criteria (say the URL is known to point to a 'naughty' image), then the image is not displayed; is that correct?
Dec 22 '07 #2

Markus
Expert 5K+
P: 6,050
Heya, Markus.

So you're saying that you want to link to an image on a different server, but if the image meets certain criteria (say the URL is known to point to a 'naughty' image), then the image is not displayed; is that correct?
That's correct.

Let me explain it a little more.

Say i have an image hosting site. Images are uploaded, URLs stored in database and images stored on the server. If an image was to be deleted, by me or whomever, but the image was still hotlinked to on say myspace, it would show an "image-deleted" image.

p.s.
Why do you write out variables like so?:
[php]
$__variable;
[/php]

thanks :)
Dec 22 '07 #3

pbmods
Expert 5K+
P: 5,821
Heya, Markus.

I'll answer your second question first. The double underscore is used when I know that a variable is "safe". In other words:

Expand|Select|Wrap|Line Numbers
  1. $__i = 0;
  2.  
I know that I declared $__i somewhere in my code, and I know its value.

On the other hand:

Expand|Select|Wrap|Line Numbers
  1. function doSomething( $param )
  2.  
When I use $param in my function, I know that I did not explicitly set the value, and I'm not 100% sure of its contents.

Generally, when I "safe" User input, I will prepend a single underscore. E.g.:
Expand|Select|Wrap|Line Numbers
  1. $_userID = (int) $userID;
  2.  
The idea here is to never use 'unsafe' variables for sensitive operations. For example, I will never do this:

Expand|Select|Wrap|Line Numbers
  1. $__sql = "SELECT * FROM `table` WHERE `id` = '{$id}' LIMIT 1";
  2.  
Instead, I will do this:
Expand|Select|Wrap|Line Numbers
  1. $_id = (int) $id;
  2. $__sql = "SELECT * FROM `table` WHERE `id` = '{$_id}' LIMIT 1";
  3.  
Now then.

My suggestion for your problem would be to create a showimage.php (or similarly-named script).

This file would take a URL as a parameter and output either the image data (don't forget to set the Content-Type header) or else a generic 'File Not Found' (or 'Deleted', etc.) image.

Something like this:
Expand|Select|Wrap|Line Numbers
  1. if( isset($_GET['image']) )
  2. {
  3.     $imageData = loadImageFromDatabase($_GET['image']);
  4. }
  5.  
  6. if( empty($imageData) )
  7. {
  8.     $imageData =
  9.         array
  10.         (
  11.             'path' => 'path/to/not/found.jpg',
  12.             'type' => 'image/jpeg'
  13.         );
  14. }
  15.  
  16. header("Content-Type: {$imageData['type']}");
  17. readfile('/path/to/images/' . basename($imageData['path']));
  18.  
The loadImageFromDatabase() function would look up the image in the database and return an empty array if the image was not found / deleted / etc.
Dec 23 '07 #4

Markus
Expert 5K+
P: 6,050
I'm not sure whether i got my point across or i don't fully understand your solution.

My thought is that the image which has been uploaded, given out a direct img url which the user can then take and embed onto their myspace page. If the image was deleted then the direct url on the myspace page would not display an image. But i've seen hosters change the image with a default one.

I'm sorry about this - i'm finding it hard to explain.

And i love the ideology behind the 'safe' variables.
Dec 23 '07 #5

pbmods
Expert 5K+
P: 5,821
Heya, Markus.

You could set up a 404 for the images directory that serves a 'file not found' image:

Put a .htaccess file in your images directory:
Expand|Select|Wrap|Line Numbers
  1. ErrorDocument 404 filenotfound.jpg
  2.  
Dec 23 '07 #6

Markus
Expert 5K+
P: 6,050
Heya, Markus.

You could set up a 404 for the images directory that serves a 'file not found' image:

Put a .htaccess file in your images directory:
Expand|Select|Wrap|Line Numbers
  1. ErrorDocument 404 filenotfound.jpg
  2.  
Thankyou very much pb.

:)
Dec 23 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.