php-windows Digest 5 Nov 2004 07:50:51 -0000 Issue 2455

Topics (messages 24885 through 24891):

Tomcat5 and PHP5
        24885 by: Dean L. Howen

Re: Headers Already Sent - How To Overcome????
        24886 by: MikeA
        24887 by: Vail, Warren
        24890 by: Andres Mora
        24891 by: Svensson, B.A.T. (HKG)

Re: Displaying An Image / Non-Web accessible Dir
        24888 by: Armando
        24889 by: Armando

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Dear friends,
Could php5 work with tomcat5?
please tell me how to make it work if could!
thanks

--- End Message ---
--- Begin Message ---
Thanks for the answer to my problem.

I tried this and it caused other problems.  Seems like the only way to get
from one place to another is with the header(Location: ) command.  I was
hoping there was something else.

So I am now kind of rewriting this guys application so it works properly.

Again, thanks for the response.

Mike


"Sudeep" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>
> Add this line at the top of the page:
>
> <?php ob_start(); ?>
>
> Your problem will be solved.
>
> ...SuDeEp...
>
> MikeA <[EMAIL PROTECTED]> wrote:
> I am trying to do the following
>
> header ("Location: wlserver/index.php?userKey=$userKey&show=$userKey");
>
> but I keep getting
>
> Warning: Cannot modify header information - headers already sent by ...
>
> The code on the header line above is not executing so I am assuming the
> previous headers being sent is causing this command to not execute. Part
of
> the problem is that I am modifying software written by someone else to fit
> my needs. I do not want to make a lot of alterations because I don't want
> to pull my hair out when the next release shows up.
>
> Is there a command or someway to get around this problem without hacking
out
> all of the other header sending code?
>
> I appreciate any help.
>
> Thank you.
>
> Mike
>
> -- 
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> ---------------------------------
> Do you Yahoo!?
>  Check out the new Yahoo! Front Page.  www.yahoo.com/a

--- End Message ---
--- Begin Message ---
Mike,

While that's not the only way to go somewhere else, if it is the way the
other guy wrote the code to get around, ripping it out an replacing it with
something else could be a problem.  The error message you are referring to
indicates that something was sent to the browser before it attempted to send
a header (usually used to get around).  One line number in the message
refers to a line of code that output something before the header function
was executed, the other to the line number of the header statement itself.

Most common causes of this is a debug message designed to show values of
variables during debug was executed before the header statement.  Solution:
either fix the bug and remove the debug display (usually an echo), or remove
or comment out the debug echo statement.  Probably the second most common
cause is switching to html mode;

Php code goes here ?> and html code goes here <?php code again ?>

In html mode even a blank line will result in stuff being sent to the
browser before the header statement is encountered.  If you nest the html
under an if statement, you can cause it not to generate output.

Hope this helps,

Warren Vail


-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of MikeA
Sent: Thursday, November 04, 2004 7:06 PM
To: [EMAIL PROTECTED]
Subject: [PHP-WIN] Re: Headers Already Sent - How To Overcome????


Thanks for the answer to my problem.

I tried this and it caused other problems.  Seems like the only way to get
from one place to another is with the header(Location: ) command.  I was
hoping there was something else.

So I am now kind of rewriting this guys application so it works properly.

Again, thanks for the response.

Mike


"Sudeep" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>
> Add this line at the top of the page:
>
> <?php ob_start(); ?>
>
> Your problem will be solved.
>
> ...SuDeEp...
>
> MikeA <[EMAIL PROTECTED]> wrote:
> I am trying to do the following
>
> header ("Location: 
> wlserver/index.php?userKey=$userKey&show=$userKey");
>
> but I keep getting
>
> Warning: Cannot modify header information - headers already sent by 
> ...
>
> The code on the header line above is not executing so I am assuming 
> the previous headers being sent is causing this command to not 
> execute. Part
of
> the problem is that I am modifying software written by someone else to 
> fit my needs. I do not want to make a lot of alterations because I 
> don't want to pull my hair out when the next release shows up.
>
> Is there a command or someway to get around this problem without 
> hacking
out
> all of the other header sending code?
>
> I appreciate any help.
>
> Thank you.
>
> Mike
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> ---------------------------------
> Do you Yahoo!?
>  Check out the new Yahoo! Front Page.  www.yahoo.com/a

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

--- End Message ---
--- Begin Message ---
how can I unsubscribe from this service????

--- End Message ---
--- Begin Message ---
> Is there a command or someway to get around this problem without
> hacking out all of the other header sending code?

Yes there is: check out out: ob_start(), ob_clean and ob_flush().

Put an ob_start() start at the very first line of your code, and just before
you send the header information, do an ob_clean(). This should clean out
anything that so far has been buffered in the out putbuffer.

--- End Message ---
--- Begin Message ---
Hi to all who volunteered assistance - I've figured out what the problem
was! Actually what the REALLY nice thing is that now that I want to
access 


-----Original Message-----
From: Armando [mailto:[EMAIL PROTECTED] 
Sent: November 2, 2004 9:47 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-WIN] Displaying An Image / Non-Web accessible Dir


Hi Jason,

I wonder if permissions are my problem, but... When I try and fopen the
file (using rb flags for read and binary) and try to do an fstat it
doesn't return any of the specific file information at all (lots of
zeros). I'm running Apache 2.0.51 under the LocalSystem account, and so
I assume that PHP which is loaded as an Apache module would attempt to
access the file as whatever user the Apache service is using. In which
case LocalSystem SHOULD have access. It's frustrating because I know I'm
probably missing something simple!

Armando

-----Original Message-----
From: Jason Barnett [mailto:[EMAIL PROTECTED] 
Sent: November 2, 2004 7:13 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP-WIN] Displaying An Image / Non-Web accessible Dir


> 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.

If all goes well, the only thing you should need to do to open that file
would 
be to open a file with a file pointer and then do whatever you want with
the 
file pointer.  Your PHP user will need read and / or write access to the
file(s) 
in question, you can right-click them to check on this.

<?php

// any file, so long as PHP user can read it
$file = 'C:\\images\\somepic.jpg';
$fp = fopen($file, 'r');
// do stuff, not sure what you wanted ewxactly but this gives you an
idea echo 'Is this a directory?  '; echo is_dir($fp) ? 'yes' : 'no';
echo '<pre>'; print_r(fstat($fp)); echo '</pre>'; // etc.

?>

-- 
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

--- End Message ---
--- Begin Message ---
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:[EMAIL PROTECTED] 
Sent: November 1, 2004 11:45 PM
To: 'PHP Windows List'
Subject: RE: [PHP-WIN] 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:[EMAIL PROTECTED] 
Sent: November 1, 2004 1:37 AM
To: Armando; PHP Windows List
Subject: RE: [PHP-WIN] 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:[EMAIL PROTECTED]
Sent: Sunday, October 31, 2004 10:29 PM
To: PHP Windows List
Subject: [PHP-WIN] 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


--- End Message ---

Reply via email to