Anyone know PHP?
#1
GTcars - Post God !
Thread Starter
Join Date: Sep 2003
Location: Macomb, Michigan
Posts: 6,032
Rep Power: 877
Anyone know PHP?
So I'm trying to make a basic script that will use an .htaccess file for a folder so that if someone tries to open a .gif, .jpg, .jpeg, file from that folder, it goes to a PHP file that makes watermarks...
So I have this as my .htacess file:
And this is my wrapper.php file:
But this is what happens when I try linking:
Anyone that knows PHP, can ya direct me as to what's going wrong? (Yeah, I know it's a red x... that's the problem.)
So I have this as my .htacess file:
AddHandler watermarked .jpg
AddHandler watermarked .jpeg
AddHandler watermarked .gif
AddHandler watermarked .png
Action watermarked /test/wrapper.php
AddHandler watermarked .jpeg
AddHandler watermarked .gif
AddHandler watermarked .png
Action watermarked /test/wrapper.php
And this is my wrapper.php file:
<?php
phpinfo(); die();
$watermark = "watermark.png";
$image = $_SERVER["PATH_TRANSLATED"];
if (empty($image)) die();
if (!file_exists($image)) {
header("404 Not Found");
echo "File Not Found."; die();
**
$outputType = getFileType($image);
watermark($image, $watermark, $outputType);
/**
Outputs the image $source with $watermark in the lower right corner.
@param $source the source image
@param $watermark the watermark to apply
@param $outputType the type to output as (png, jpg, gif, etc.)
defaults to the image type of $source if left blank
*/
function watermark($source, $watermark, $outputType="") {
$sourceType = getFileType($source);
$watermarkType = getFileType($watermark);
if (empty($outputType)) $outputType = $sourceType;
header("Content-type:image/$outputType");
// Derive function names
$createSource = "ImageCreateFrom".strtoupper($sourceType);
$showImage = "Image".strtoupper($outputType);
$createWatermark = "ImageCreateFrom".strtoupper($watermarkType);
// Load original and watermark to memory
$output = $createSource($source);
$logo = $createWatermark($watermark);
ImageAlphaBlending($output, true);
// Find proper coordinates so watermark will be in the lower right corner
$x = ImageSX($output) - ImageSX($logo);
$y = ImageSY($output) - ImageSY($logo);
// Display
ImageCopy($output, $logo, $x, $y, 0, 0, ImageSX($logo), ImageSY($logo));
$showImage($output);
// Purge
ImageDestroy($output);
ImageDestroy($logo);
**
function getFileType($string) {
$type = strtolower(eregi_replace("^(.*)\.","",$string));
if ($type == "jpg") $type = "jpeg";
return $type;
**
phpinfo(); die();
$watermark = "watermark.png";
$image = $_SERVER["PATH_TRANSLATED"];
if (empty($image)) die();
if (!file_exists($image)) {
header("404 Not Found");
echo "File Not Found."; die();
**
$outputType = getFileType($image);
watermark($image, $watermark, $outputType);
/**
Outputs the image $source with $watermark in the lower right corner.
@param $source the source image
@param $watermark the watermark to apply
@param $outputType the type to output as (png, jpg, gif, etc.)
defaults to the image type of $source if left blank
*/
function watermark($source, $watermark, $outputType="") {
$sourceType = getFileType($source);
$watermarkType = getFileType($watermark);
if (empty($outputType)) $outputType = $sourceType;
header("Content-type:image/$outputType");
// Derive function names
$createSource = "ImageCreateFrom".strtoupper($sourceType);
$showImage = "Image".strtoupper($outputType);
$createWatermark = "ImageCreateFrom".strtoupper($watermarkType);
// Load original and watermark to memory
$output = $createSource($source);
$logo = $createWatermark($watermark);
ImageAlphaBlending($output, true);
// Find proper coordinates so watermark will be in the lower right corner
$x = ImageSX($output) - ImageSX($logo);
$y = ImageSY($output) - ImageSY($logo);
// Display
ImageCopy($output, $logo, $x, $y, 0, 0, ImageSX($logo), ImageSY($logo));
$showImage($output);
// Purge
ImageDestroy($output);
ImageDestroy($logo);
**
function getFileType($string) {
$type = strtolower(eregi_replace("^(.*)\.","",$string));
if ($type == "jpg") $type = "jpeg";
return $type;
**
But this is what happens when I try linking:
Anyone that knows PHP, can ya direct me as to what's going wrong? (Yeah, I know it's a red x... that's the problem.)
#7
GTcars - Post God !
Thread Starter
Join Date: Sep 2003
Location: Macomb, Michigan
Posts: 6,032
Rep Power: 877
Yeah, Chad got it. I looked at the web statistics of my site and noticed that like 20+ people were hotlinking images off my site and posting it on other forums and stuff, so I decided to take care of that!
Thread
Thread Starter
Forum
Replies
Last Post
mz.pasillas_o7_27_07
honda / acura
0
11-08-2008 09:47 PM
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)