RE: Displaying An Image / Non-Web accessible Dir

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Warren, Jason, and everyone else who volunteered answers to this -
and sorry about my other partial emails... Wrong hotkeys :-)

The good news is I figured out what I was doing wrong and thought I'd
let you know. It turns out that in my showpic.php page which is called
from an <img src> tag on another page, this is all the code I needed to
display an image:

<?php
header("Content-type: image/jpeg");
$file = "c:\\my\\path\\images\\file_name.jpg";
$im = imagecreatefromjpeg($file);
imagejpeg($im);
imagedestroy($im);
?>

This of course is just the very basics. The $file will be built
dynamically from ? parameters passed from the img tag. Even better news
is that after more testing, I found that by modifying the $file path I
can get to any image file on my C: drive (http-accessible or not) and
have the image display without needing to write a bunch of extra
filesystem and/or binary read/stream function-related code that I had to
in vbscript on my asp pages.

I guess when the gd functions do the image creation, it grabs the image
from the physical location on the drive that $file specifies without
needing any extra functions. Needless to say this is going to
significantly reduce the amount and complexity of my code, and is quite
an extremely pleasant surprise! Cheers to all.

Armando

-----Original Message-----
From: Armando [mailto:dijital@xxxxxxx] 
Sent: November 1, 2004 11:45 PM
To: 'PHP Windows List'
Subject: RE:  Displaying An Image / Non-Web accessible Dir


Thanks for the information Warren.

I am actually already passing parameters to the page for the file types
(at least I was in ASP and will now do so in PHP as well) and I'm pretty
sure I can figure out how to get the image created with your
recommendations below now that I enabled the GD libs and verified
they're working with a var_dump of gd_info().

What my problem really is right now is I can't seem to use the
filesystem objects to open an image file from somewhere on my drive.
What I'd like to do just to test is at least display the filesize of an
image (for the content-length header and to display the filesize of an
image on my page) and I can't seem to get it to work. I've tried using
fopen, fread, readfile, and others but honestly I'm still very new and
not sure how to go about doing this so not even sure which object I
need.

Can you or someone suggest how I can access an image file on my drive
which is not part of the http-accessible directories (say in
C:\images\somepic.jpg) and display the filetype? I think once I can at
least get that to work, the rest should be fairly simple.

FYI - I'm running PHP 5.0.2 , http server is Apache 2.0.51, and o/s is
Win2K Server. Thanks again, and cheers.

Armando

-----Original Message-----
From: Warren Vail [mailto:warren@xxxxxxxxxxxx] 
Sent: November 1, 2004 1:37 AM
To: Armando; PHP Windows List
Subject: RE:  Displaying An Image / Non-Web accessible Dir


I would thing you could do something similar using the GD "image"
functions,

http://www.php.net/manual/en/ref.image.php

in your html page code <img src="path/to/imagemodule.php"> and this
module would

basically;
	1. determine the type of image (jpec, gif, etc) (note you can
pass ?parms in get format to your imagemodule
	   in the src reference above)
	2. output the correct mime headers for that type of image
http://www.php.net/manual/en/function.header.php
		header('Content-type: image/jpeg');
		header('Content-Length: $len');
	3. $img = imagecreatefromxxx("/full/path/to/image/file.xxx")
where xxx is the type of image

	----- here you have an opportunity to do all kinds of things
like resize the image to a thumbnail, add text
            overlays, etc.

	4. imagexxx($img); where xxx is the type of image actually will
output the image behind the headers
	....that's all there is

If there are better PHP options, hopefully someone will provide them
here.

Good Luck,

Warren Vail

-----Original Message-----
From: Armando [mailto:dijital@xxxxxxx]
Sent: Sunday, October 31, 2004 10:29 PM
To: PHP Windows List
Subject:  Displaying An Image / Non-Web accessible Dir


Greetings!

I'm porting all my old ASP websites to PHP and have run into a small
problem. One of my pages is a gallery in which images can (should) only
be viewed by authenticated users in my MySQL database. The images are
stored in a non-web accessible directory. For example.. say my root
website is in 'C:\www\webroot' and the gallery images are in
'C:\www\gallery'.

On my ASP page what I did was have the <img> tag call to an ASP page
which would open the file from the actual location on the disk, then
stream it to the page. ASP's filesystemobject and adodb stream
references open the file and do a binary-write to the page to display
the image. Since the page is ASCII and the image data is binary, you
cannot mix the two on the same page,  hence the reason for the <img> tag
calling to a separate ASP page.

Now my problem is I'd like to do the same thing in PHP but am not
exactly sure how to go about doing this. I've tried a number of the
filesystem references, but have had no luck so far. I'm assuming I have
to do a similar thing by having my <img> tag call to a PHP page to get
the image, which is easy enough, but I can't figure out how to display
the image from that page. I'm just not familiar enough with PHP yet to
do this.

Any help would be greatly appreciated! Cheers.

Armando

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux