• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.

Redirect to an image.jpg.html

Avast

👽 Chevereto Freak
Hey,

i know that this was already asked , but i can't find it.
I want to redirect the user to a "view"-page of the image , if he clicks on the directlink.
So if someone embed the bb-code (preview, click=redirect to the image | not viewer!), he'll be redirected to an html version like this:
http://www.pic-upload.de/view-14106204/Tulips.jpg.html


Does anyone know how to do this?
 
It should be doable now using the class.filelist and a standard hotlink protection htaccess configuration if you create a new page to redirect to when a user attempts to access an image directly by redirecting the user to a handler.php page that will accept the image name.
 
It is possible for the redirect, however, I cannot find a way to differentiate between a hotlink or a direct request that will work 100% to serve a hotlink image to handler. The below steps will work if you don't care about your hotlinked images showing as broken images.

Remove any hotlink protection code and replace with this (change example.com to your domain in 3 locations below):

Code:
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{HTTP_REFERER} !search\?q=cache [NC]
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !slurp\. [NC]
RewriteCond %{HTTP_REFERER} !mmcrawler\. [NC]
RewriteCond %{HTTP_REFERER} !msnbot\. [NC]
RewriteCond %{HTTP_REFERER} !sandcrawler\. [NC]
RewriteCond %{HTTP_REFERER} !msrbot\. [NC]
RewriteCond %{HTTP_REFERER} !teoma\. [NC]
RewriteCond %{HTTP_REFERER} !jeeves\. [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?domain\.com [NC]
RewriteCond %{REQUEST_FILENAME} !hotlink\.jpg$ [NC]
RewriteCond %{REQUEST_FILENAME} !image\.php [NC]
RewriteCond %{REQUEST_FILENAME} !\.th\. [NC]
RewriteCond %{REQUEST_URI} ^(.*) [NC]
RewriteRule images/.+\.(gif|jpe?g|png|bmp) http://domain.com/image.php?f=http://domain.com%1 [NC,L]

Create a new page in the web root named image.php with the following contents:

PHP:
<?php
if (isset($_GET['f'])) {
    define('access', 'index');
    $f = filter_var($_GET['f'],FILTER_SANITIZE_URL);
    if (!$f) { die(); }
    if(!@include_once('includes/chevereto.php')) die('Can\'t find includes/chevereto.php');
    require_once(__CHV_PATH_CLASSES__.'class.filelist.php');
    $myList = new FileList();
    $myList = $myList->filelist;
    foreach($myList as $myEntry){
        if($f == $myEntry['image_url']){
            $location = $myEntry['image_viewer'];
            break;
        }
    }
    header("Location: $location");
}
 
// The code to send hotlink image to browser if hotlinked.
// Current;y, I have not found a guaranteed way to achieve this
// As is this code probably will never fire.
 
    $file = "hotlink.jpg";
    $fs = stat($file);
    header("Content-Type: image/jpeg");
    header("Etag: ".sprintf('"%x-%x-%s"', $fs['ino'], $fs['size'],base_convert(str_pad($fs['mtime'],16,"0"),10,16)));
    $size = filesize($file);
    header("Content-Length: $size");
    header("Last-Modified: " .gmdate("D, d M Y H:i:s")." GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    header("Pragma: no-cache");
    header("Keep-Alive: timeout=5, max=100");
    header("Connection: Keep-Alive");
    $fh = fopen($file, "rb");
    while ( ($buf=fread( $fh, 1024 * 8 )) != '' )
    {
        set_time_limit(0);
        echo $buf;
        flush();
    }
    fclose($fh);
 
die();

define('access', 'index') was added because access must be defined and I didn't feel like looking around to see what all options were available to get around this.

The bottom of my code is likely to never actually fire, this is the section that I would like to know how to handle. If anyone has any suggestions, please let me know.

Another important note is higher in my .htaccess I have defined the domain to always be without www. If you have done the inverse, you need to make the appropriate changes.

In some cases, I am noticing my browser won't render the image once it gets to the appropriate viewer page. I think this could be an issue with caching from the previous request. Perhaps adding a void querystring to your img src tag on the viewer page could solve this.
 
Back
Top