Search code examples
phpapache.htaccessmod-rewritemybb

redirect access (php code) to image file by htaccess


in mybb forum the attachments images are stored into subfolders of "uploads" folder, one subfolder for month 201401,201402.....

what i need to do is to redirect the access to the image file when attachment.php page read it.

the attachment has original image extension for Thumbnail and .attach for normal size copy.

this is the php code that read the image:

header("Content-length: {$attachment['filesize']}");
header("Content-range: bytes=0-".($attachment['filesize']-1)."/".$attachment['filesize']);
$handle = fopen($mybb->settings['uploadspath']."/".$attachment['attachname'], 'rb');
while(!feof($handle))
{
    echo fread($handle, 8192);
}
fclose($handle);

so i created .htaccess into uploads folder:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(gif|jpeg|jpg|png|attach)$ watermark.php [QSA,NC]

the forum is hosted on altervista.org why no redirect occurs to watermark.php?


Solution

  • It could well be that the parent folder has an .htaccess as well, which causes trouble. Please show me the parent's' folders' .htaccess.

    [edit] Apart from the problem that the parent folder it's .htaccess might cause, htaccess does not come into play when PHP reads from the filesystem with fopen. You should integrate the logic from watermark.php into the image reading php file..