473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

passing a filename & content type as image


I'm trying to pass a filename (which is a jpeg image) to a php
function / file so that it will display. I know that its simple
to get PHP to display an image hardcoding in the filename. For
example, an href to this:

<?php
header("content-type:image/jpeg");
$filename = "image_file.jpg";
$im=ImageCreateFromJPEG($filename);
ImageJPEG($im);
?>

But when I have a filename I create dynamically in PHP and try to
call a php function with the filename, for example calling:

<?php
display_jpeg_file($image_path);
?>

<?php
function display_jpeg_file($filename) {
header("content-type:image/jpeg");
$im=ImageCreateFromJPEG($filename);
ImageJPEG($im);
}
?>

I get the "cannot modify header information" error. The error
message always refers to a php function early in the phmtl page.
So somehow it sees this function as a continuation of the existing
html document. How do I arrange the function call to my display
function so that it works? Or, if my approach is all wrong, what
is the correct approach? The important part is I have a filename
generated in PHP that I want to display.

Thanks in advance for any help.

B Squared

================================================== =============
Self esteem, n. An erroneous appraisement
-- Ambrose Bierce, The Devils Dictionary


Jan 26 '06 #1
4 2488

B Squared wrote:
I'm trying to pass a filename (which is a jpeg image) to a php
function / file so that it will display.


I think you can simply use readfile() to read the file and pass it
through to the browser.

Jan 26 '06 #2
d
"B Squared" <nu**@null.com> wrote in message
news:Bb******************************@scnresearch. com...

I'm trying to pass a filename (which is a jpeg image) to a php
function / file so that it will display. I know that its simple
to get PHP to display an image hardcoding in the filename. For
example, an href to this:

<?php
header("content-type:image/jpeg");
$filename = "image_file.jpg";
$im=ImageCreateFromJPEG($filename);
ImageJPEG($im);
?>
Why don't you just use readfile() instead of imagecreatefromjpeg? You only
really need to use the image functions if you're manipulating images, not if
you're just displaying them.
But when I have a filename I create dynamically in PHP and try to
call a php function with the filename, for example calling:

<?php
display_jpeg_file($image_path);
?>

<?php
function display_jpeg_file($filename) {
header("content-type:image/jpeg");
$im=ImageCreateFromJPEG($filename);
ImageJPEG($im);
}
?>

I get the "cannot modify header information" error. The error
message always refers to a php function early in the phmtl page.
So somehow it sees this function as a continuation of the existing
html document. How do I arrange the function call to my display
function so that it works? Or, if my approach is all wrong, what
is the correct approach? The important part is I have a filename
generated in PHP that I want to display.
You can't send headers if you've already outputted (unless you use output
buffering). Why are you outputting something before the image? The image
won't work if you have any output before or after it in the same document.
If you want to get a PHP page to show an image, include a standard HTML
<img> tag with the src pointing to your PHP script. If you stil need to
pass it another filename, you can put that in the query string
(base64_encode it so it's url-safe, and base64_decode it the other end to
get the filename out).

does that make sense?
Thanks in advance for any help.

B Squared
dave
================================================== =============
Self esteem, n. An erroneous appraisement
-- Ambrose Bierce, The Devils Dictionary

Jan 26 '06 #3
d wrote:
"B Squared" <nu**@null.com> wrote in message
news:Bb******************************@scnresearch. com...
I'm trying to pass a filename (which is a jpeg image) to a php
function / file so that it will display. I know that its simple
to get PHP to display an image hardcoding in the filename. For
example, an href to this:

<?php
header("content-type:image/jpeg");
$filename = "image_file.jpg";
$im=ImageCreateFromJPEG($filename);
ImageJPEG($im);
?>

Why don't you just use readfile() instead of imagecreatefromjpeg? You only
really need to use the image functions if you're manipulating images, not if
you're just displaying them.


Excellent suggestion. I tried this, and it does just what I need.
But when I have a filename I create dynamically in PHP and try to
call a php function with the filename, for example calling:

<?php
display_jpeg_file($image_path);
?>

<?php
function display_jpeg_file($filename) {
header("content-type:image/jpeg");
$im=ImageCreateFromJPEG($filename);
ImageJPEG($im);
}
?>

I get the "cannot modify header information" error. The error
message always refers to a php function early in the phmtl page.
So somehow it sees this function as a continuation of the existing
html document. How do I arrange the function call to my display
function so that it works? Or, if my approach is all wrong, what
is the correct approach? The important part is I have a filename
generated in PHP that I want to display.

You can't send headers if you've already outputted (unless you use output
buffering).Why are you outputting something before the image?


I want to place some text above the image, and control the font and
background color. Typical HTML to pretty up the appearance of the page.
The image
won't work if you have any output before or after it in the same document.
If you want to get a PHP page to show an image, include a standard HTML
<img> tag with the src pointing to your PHP script. If you stil need to
pass it another filename, you can put that in the query string
(base64_encode it so it's url-safe, and base64_decode it the other end to
get the filename out).


I understand in part. Here's the deal. The filepathname for the image
to be displayed comes from a database query that's inside a PHP script.
So it really is dynamically generated. So, referring to your method of
encoding the filename, it looks like (if I understand you) that I need
to pass the data I retrieve inside PHP back out to html, so that html
can format the strings, and, using the <img> tag, call another PHP
file to display the image. It seems a bit complicated, but I can do
that. How do I pass the strings from PHP to html. A simple example
of how to do this would be *greatly* appreciated. If I understand
you, this is the only part of the solution I don't know how to do.

Thanks in advance.

B Squared
Jan 27 '06 #4

Never mind my last comment,

I got it figured out.

B Squared.
"B Squared" <nu**@null.com> wrote in message
news:Bb******************************@scnresearch. com...
I'm trying to pass a filename (which is a jpeg image) to a php
function / file so that it will display. I know that its simple
to get PHP to display an image hardcoding in the filename. For
example, an href to this:

<?php
header("content-type:image/jpeg");
$filename = "image_file.jpg";
$im=ImageCreateFromJPEG($filename);
ImageJPEG($im);
?>

Why don't you just use readfile() instead of imagecreatefromjpeg? You only
really need to use the image functions if you're manipulating images, not if
you're just displaying them.

But when I have a filename I create dynamically in PHP and try to
call a php function with the filename, for example calling:

<?php
display_jpeg_file($image_path);
?>

<?php
function display_jpeg_file($filename) {
header("content-type:image/jpeg");
$im=ImageCreateFromJPEG($filename);
ImageJPEG($im);
}
?>

I get the "cannot modify header information" error. The error
message always refers to a php function early in the phmtl page.
So somehow it sees this function as a continuation of the existing
html document. How do I arrange the function call to my display
function so that it works? Or, if my approach is all wrong, what
is the correct approach? The important part is I have a filename
generated in PHP that I want to display.

You can't send headers if you've already outputted (unless you use output
buffering). Why are you outputting something before the image? The image
won't work if you have any output before or after it in the same document.
If you want to get a PHP page to show an image, include a standard HTML
<img> tag with the src pointing to your PHP script. If you stil need to
pass it another filename, you can put that in the query string
(base64_encode it so it's url-safe, and base64_decode it the other end to
get the filename out).

does that make sense?

Thanks in advance for any help.

B Squared

dave

================================================ ===============
Self esteem, n. An erroneous appraisement
-- Ambrose Bierce, The Devils Dictionary


Jan 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Gregory | last post by:
Hello, I'm trying to do the above in order to process an image and return the result to an html image control. It fails and my key suspects are either the variable that I'm passing in -...
3
by: Shawn Wilson | last post by:
Hi, I've created a PHP file called filename.jpg. It outputs a JPG. I've set up a .htaccess file to force the filetype to PHP. The file is displayed in a page on a browser. I cannot get the...
2
by: curwen | last post by:
Hi, I have problem to create a well formed xsl-fo document using images dynamically generated from an http request using this tag: <fo:external-graphic content-type="content-type:image/gif"...
0
by: Sarah Akers | last post by:
GgF ----gL5cJ72EqiGIQ0SK65Rz Content-Type: text/html; Content-Transfer-Encoding: quoted-printable <html> <head> <style type=3D"text/css">.eyebrow { FONT-WEIGHT: bold; FONT-SIZE: 10px; TE=
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
2
by: eholz1 | last post by:
Hello PHP Group, I have a php page that calls another php page to load a image from a database (mysql) in to the calling page. It works like this: first_view.php has <img src="image.php?img=5"...
3
by: KimberlyM | last post by:
This has been driving me crazy. I hope someone can help. The site displays perfectly in FF but all div's do not show in IE. Please help me find the problem! Thanks! Here is my css. ...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.