You are here: Re: Images and PHP « All PHP « IT news, forums, messages
Re: Images and PHP

Posted by robert on 04/25/06 22:00

"The Numerator" <alvin4jesus@gmail.com> wrote in message
news:1145849539.405551.3470@t31g2000cwb.googlegroups.com...
|I have a folder full with images, and for security reasons I don't want
| anyone to know where the folder is. So, to call images, I know there is
| a way to call like a PHP file instead. For example Galley 2 (a
| PHP-enabled photo album) safetly tucks away the actual images and in
| the image source, it calls for something like
| "main.php?g2_view=core.DownloadItem&g2_itemId=12&g2_serialNumber=3".
|
| How do you do that? Do you need to use the database to do this? Thank
| you.

i don't normally do this, but i'm going to paste source. (sorry about the
text wrapping). do NOT store images in a db as this limits your options when
you consider migrating from one db to another and the amount of code that
could need changes. it's a pain in the ass. the following requires the gdi
lib. anyway, here's how to call this first set of code (generates a
thumbnail of an image and when clicked, opens the actual file):

note that i include a config page with a "site" class that stores info about
the web site...$site->uri would be like "http://www.mysite.org/"...you'll
notice other functions that come from my functions.inc.php script...just
modify what you need to - even hard code for now.

<a
href="<?= $site->uri ?>get.file.php?fileName=blah.jpg"
style="font-size:8pt;"
target="VIEW_FILE"
>
<img
src="<?= $site->uri ?>get.thumb.nail.php?fileName=blah.jpg&maxSize=200"
alt="File Not Found!"
title="Click To Open: blah.jpg"
/>
blah.jpg
</a>


====== contents of get.thumb.nail.php ========

<?
require_once 'site.cfg.php';
require_once $site->includeDirectory . 'functions.inc.php';
$fileName = $_REQUEST['fileName'] ? $_REQUEST['fileName'] :
$_REQUEST['altImage'];
$maxSize = $_REQUEST['maxSize'] ? $_REQUEST['maxSize'] : 200;
$filePath = $site->imagesDirectory;
if (!(isSupportedImage($fileName) || isSupportedMedia($fileName)))
{
$fileName = isSupportedMedia($fileName) ? 'media.jpg' :
'document.jpg';
}
$fileData = @file_get_contents($filePath . $fileName);
$originalImage = @imagecreatefromstring($fileData);
@list($imageWidth, $imageHeight, $imageType, $imageAttributes) =
@getimagesize($filePath . $fileName);
$newImageHeight = $imageWidth < $maxSize ? $imageHeight : ($imageHeight /
$imageWidth) * $maxSize;
$newImageWidth = $imageWidth < $maxSize ? $imageWidth : $maxSize;
$thumbNail = @imagecreatetruecolor($newImageWidth, $newImageHeight);
@imagecopyresampled(
$thumbNail,
$originalImage,
0,
0,
0,
0,
$newImageWidth,
$newImageHeight,
@imagesx($originalImage),
@imagesy($originalImage)
);
@imagejpeg($thumbNail);
@imagedestroy($thumbNail);
@imagedestroy($originalImage);
?>

===========

======= contents of get.file.php ==========

<?
require_once 'site.cfg.php';
$fileData = '';
$fileName = $_REQUEST['fileName'];
$filePath = $site->uploadBaseDirectory;
if ($fileName != ''){ $fileData = @file_get_contents($filePath .
$fileName); }
header("content-type: application/octet-stream" );
header("content-size: " . count($fileData) );
header("content-disposition: inline; filename=$fileName");
echo $fileData;
?>

===========

hth,

me

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация