The Little Guy Posted October 25, 2007 Share Posted October 25, 2007 When an image doesn't exist at imageshack, imageshack sends this image to the client instead of a blank image. how do they do it? Quote Link to comment Share on other sites More sharing options...
premiso Posted October 25, 2007 Share Posted October 25, 2007 All images are ported to a central file, images.php via .htaccess From there they use the url to determine if the file exists, if not the images.php prints out the generic 404 for images. If it does it goes and retrieves the file and print that out instead. Quote Link to comment Share on other sites More sharing options...
Orio Posted October 25, 2007 Share Posted October 25, 2007 Basically it should look like this: <?php if(!file_exists($_GET['filename'])) echo '<img src="default.jpg">'; else echo '<img src="'.$_GET['filename'].'">'; ?> Orio. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 25, 2007 Author Share Posted October 25, 2007 how would the .htaccess file look? Quote Link to comment Share on other sites More sharing options...
premiso Posted October 25, 2007 Share Posted October 25, 2007 Options +FollowSymlinks RewriteEngine on RewriteRule ^(.*)\.jpg$ images.php [nc] Since I believe the best way to learn is by reading it yourself look http://httpd.apache.org/docs/1.3/misc/rewriteguide.html For a full guide on how to create a mod rewrite htaccess file (look at the rewritecond and rewriterule). Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 25, 2007 Author Share Posted October 25, 2007 OK, Here is what I have: - DB - Members: stores file name - Guests: stores file name and directory (I have a few directory's the file is randomly placed into) Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 26, 2007 Author Share Posted October 26, 2007 Options +FollowSymlinks RewriteEngine on RewriteRule ^(.*)\.jpg$ images.php [nc] Will that still work, even if the images are being displayed on a foum? or on some other website? Quote Link to comment Share on other sites More sharing options...
premiso Posted October 26, 2007 Share Posted October 26, 2007 Options +FollowSymlinks RewriteEngine on RewriteRule ^(.*)\.jpg$ images.php [nc] Will that still work, even if the images are being displayed on a foum? or on some other website? Should it takes any request and routes it through images.php Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 26, 2007 Author Share Posted October 26, 2007 OK... I think there is something wrong.... I upload the image but I can not view it in the browser? If I remove that code from the .htaccess file, then refresh the image, it displays, then If I put it back it doesn't display.. Quote Link to comment Share on other sites More sharing options...
premiso Posted October 26, 2007 Share Posted October 26, 2007 Remember that you need to use www.php.net/header and www.php.net/readfile The header you need to set the content-type to be jpeg and the readfile is to basically display the image from the file. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 26, 2007 Author Share Posted October 26, 2007 so... if I have this: <?php if(!file_exists($_GET['filename'])) echo '<img src="http://tzfiles.com/imageNotFound.jpg">'; else echo '<img src="'.$_GET['filename'].'">'; ?> Would I place it like this: <?php readfile('imageNotFound.jpg'); header('Content-type: images/jpeg'); if(!file_exists($_GET['filename'])) echo '<img src="http://tzfiles.com/imageNotFound.jpg">'; else echo '<img src="'.$_GET['filename'].'">'; ?> Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 26, 2007 Author Share Posted October 26, 2007 OK... Now the image displays, but even if the image does exist, it still displays the imageNotFound.jpg file... Quote Link to comment Share on other sites More sharing options...
premiso Posted October 26, 2007 Share Posted October 26, 2007 <?php header('Content-type: images/jpeg'); if(!file_exists($_GET['filename'])) readfile("http://tzfiles.com/imageNotFound.jpg"); else readfile($_GET['filename']); ?> In order for it to be interpreted as an image it must be read and written to the browser as an image. The img src is part of html, which is not part of an image file. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 26, 2007 Author Share Posted October 26, 2007 OK... but images are still not displaying, even if they do exist, it is displaying the imageNotFound.jpg file instead. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 26, 2007 Author Share Posted October 26, 2007 OK... I got it Quote Link to comment Share on other sites More sharing options...
premiso Posted October 26, 2007 Share Posted October 26, 2007 Implement some debugging standards. What is the filename printing out? Is it printing out the full path or not? You should probably add the full path to it, as the .htaccess rewrite changes the directory to be where the images.php file is. So even though the url is pointing to /images/etc.jpg the relative path would be /image.php so you would then need to add that into the get string. The script will work like it is suppose to, you just have to have the full path to the file. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 26, 2007 Author Share Posted October 26, 2007 It works now... I need to add support for more than one file type though, like: gif and png. What would I have to do to my htaccess file? Options +FollowSymlinks RewriteEngine on RewriteRule ^(.*)\.jpg$ images.php?filename=$1.jpg [nc] Quote Link to comment Share on other sites More sharing options...
premiso Posted October 26, 2007 Share Posted October 26, 2007 Options +FollowSymlinks RewriteEngine on RewriteRule ^(.*)\.(jpg|gif|png)$ images.php?filename=$1 [nc] I am not sure how to send it in the filename...but that will send the gif and png files also to images.php Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted October 26, 2007 Author Share Posted October 26, 2007 Looks like it needs to look like this: Options +FollowSymlinks RewriteEngine on RewriteRule ^(.*\.(jpg|gif|png))$ images.php?filename=$1 [nc] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.