php-windows Digest 18 Jan 2005 09:28:03 -0000 Issue 2540
Topics (messages 25361 through 25378):
Re: including an HTML file
25361 by: Randy Clamons
Output Image from Db to Browser
25362 by: MikeA
25367 by: graeme
25371 by: MikeA
25375 by: graeme
Re: help w/hidden fields and storing an int.
25363 by: Jason Barnett
25364 by: Patrick Roane
I am trying to write & read to a file
25365 by: Patrick Roane
25368 by: graeme
Re: Newbie question: convert string to int
25366 by: graeme
Tool to convert delphi to php
25369 by: Louis Young
PHP5 MSSQL and FreeTDS
25370 by: Frank M. Kromann
Php And Mail
25372 by: Dean Hayes
25376 by: David Elliott
Browscap.ini
25373 by: Hassan Shaikh
PHP doesn't like COM
25374 by: Louis Young
Pre-selecting country
25377 by: Zu3Bi
Stored proc
25378 by: Louis Young
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 ---
True enough, fread reads the entire file contents into RAM, and that could be a
problem. On the other hand, if it is not a problem--if the file to be read is
not too big--it's more efficient and there is less code to maintain. The
regular expression in my example extracts the appropriate part of the file,
there is no need to check individual lines of content.
Your code is returning the entire file, excluding whatever is contained in the
<HEAD>...</HEAD>. It seems likely that if the entire file uses too much memory,
the part your code returns is probably going to use too much memory as well.
The other problem with your code here is that is does not take into account any
properties of the body tag that may exist, such as bgcolor, link, etc. Leaving
the closing bracket off the <BODY> tag would probably take care of this.
There is always more than one way to accomplish any task. You'll just have to
pick one that suits your needs.
Randy Clamons
Systems Programming
Astro-auction.com
> ------------Original Message------------
> From: The Disguised Jedi <[EMAIL PROTECTED]>
> To: [email protected]
> Date: Sun, Jan-16-2005 2:28 PM
> Subject: Re: [PHP-WIN] including an HTML file
>
> Well, fread reads the entire file, and we need to check the lines to
> see if they contain our tag, and so that is why i used fgets. fread
> also puts the entire file into RAM, and that can cause memory problems
> with large files. But, I forgot a few pieces of my function, so I'm
> adding a better version.
>
> <?php
>
> $filename = 'ourfile.html';
> $tag = '<BODY>';
> $closing_tag = '</BODY>';
>
> function insert_html($filename, $tag, $closing_tag) {
> //Open the HTML file
> $handle = fopen($filename, 'r');
>
> $i = 0;
> //As long as the file reader isn't at the end of the file, keep
> looping through
> while (!feof($handle)) {
> //Read through our file in 4MB chunks, or by line, whichever
> comes
> first...
> $buffer = fgets($handle, 4096);
> //Search our buffer for the tag. If it is there, we tell the
> rest
> of the program to start saving out the text...
> if (strstr($buffer, $tag) == $tag) {
> $save = true;
> }
> if ($save == true) {
> $file[$i] = $buffer;
> $i++;
> }
> if (strstr($buffer, $closing_tag) == $closing_tag) {
> $save = false;
> }
> }
> //Put the data all together, and send it back...
> while (current($file)) {
> $data .= '
> ' . current($file);
> }
> return $data;
> }
>
> ?>
>
> I forgot to add the part that tells it to check for when to stop
> saving. This should suit your needs Gaetono, let me know if it
> doesn't work right!
>
>
> --
> The Disguised Jedi
> [EMAIL PROTECTED]
>
> PHP rocks!
> "Knowledge is Power. Power Corrupts. Go to school, become evil"
>
> Disclaimer: Any disclaimer attached to this message may be ignored.
> This message is Certified Virus Free
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
I am trying to output a JPG image to the browser without creating a file. I
have tried several
things but nothing seems to work. I sure could use a whole lot of help right
now! LOL Going crazy
trying to figure this out. But I know there are PHP gurus out there that will
have the answer in 2
seconds. Hopefully I'll be at that level someday too!
The image comes from a MySQL Blob. The closest I get is a string of garbage on
the browser display.
I cannot get it to display a pictures.
Suggestions, comments, help, almost anything is appreciated. PLEASE help me!
Project due in a week.
Thanks in advance.
Mike
if( mysql_num_rows($result) == 1 )
{
//header('Content-type: image/*');
$fileContent = mysql_result($result,0); //,$blobfield);
echo $fileContent;
//$theimage = imagecreatefromstring ($fileContent);
//echo imagejpeg ( $theimage);
--- End Message ---
--- Begin Message ---
Sorry running from memory here. You need to set your output headers to
display a jpg not text. So you need something like:
header("Content-type: image/jpg");
This will display the image on its own, if you need to embed the image
in a web page you need a little more trickery. I'll try to look it up
for you. But this should at least get you going on testing getting your
image from the database.
graeme
MikeA wrote:
I am trying to output a JPG image to the browser without creating a file. I
have tried several
things but nothing seems to work. I sure could use a whole lot of help right
now! LOL Going crazy
trying to figure this out. But I know there are PHP gurus out there that will
have the answer in 2
seconds. Hopefully I'll be at that level someday too!
The image comes from a MySQL Blob. The closest I get is a string of garbage on
the browser display.
I cannot get it to display a pictures.
Suggestions, comments, help, almost anything is appreciated. PLEASE help me!
Project due in a week.
Thanks in advance.
Mike
if( mysql_num_rows($result) == 1 )
{
//header('Content-type: image/*');
$fileContent = mysql_result($result,0); //,$blobfield);
echo $fileContent;
//$theimage = imagecreatefromstring ($fileContent);
//echo imagejpeg ( $theimage);
--
Experience is a good teacher, but she sends in terrific bills.
Minna Antrim
--- End Message ---
--- Begin Message ---
I had tried that once but then I was requested the download the file. But I
gave your suggestion a
shot and I am getting an error message saying there is an error in the JPG file.
BTW, looking back at my original post I accidentally left out how I was calling
the function. I used
this first.
<img src="get_image('sub','s_sub_code', $row['s_sub_code'], 's_map')">
Then I tried
get_image('sub','s_sub_code', $row['s_sub_code'], 's_map');
But I get that error in JPG message each time. So I am getting a little more
closer. Here is how
the function looks now. The things I tried are commented out so I won't forget
what I did.
function get_image($table, $pk_name, $pk_value, $blobfield)
{
login();
$query = 'SELECT '.$blobfield;
$query .= ' FROM '.$table;
$query .= ' WHERE '.$pk_name." = '".$pk_value."'";
//echo "<P>q=".$query."<P>";
$result = mysql_query( $query ) or die ("<P>Could not get image<P>");
if(mysql_num_rows($result) == 1 )
{
header('Content-type: image/jpeg');
//header('Content-type: image/*');
$fileContent = mysql_result($result,0); //,$blobfield);
$theimage = imagecreatefromstring ($fileContent);
echo imagejpeg ($theimage);
//echo $fileContent;
//header('Content-type: ' . image_type_to_mime_type(IMAGETYPE_WBMP));
//image2wbmp($image); // output the stream directly
}
But I am trying to put it in a table in the browser. If I can get the JPG to at
least show up I
should be able to adjust it using a STYLE setting or TABLE. It is just getting
it to output that has
got me stumped so far.
Thanks every so much for your help so far. Hope you can find the rest of it.
Thanks.
Mike
"graeme" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
Sorry running from memory here. You need to set your output headers to
display a jpg not text. So you need something like:
header("Content-type: image/jpg");
This will display the image on its own, if you need to embed the image
in a web page you need a little more trickery. I'll try to look it up
for you. But this should at least get you going on testing getting your
image from the database.
graeme
MikeA wrote:
>I am trying to output a JPG image to the browser without creating a file. I
>have tried several
>things but nothing seems to work. I sure could use a whole lot of help right
>now! LOL Going crazy
>trying to figure this out. But I know there are PHP gurus out there that will
>have the answer in 2
>seconds. Hopefully I'll be at that level someday too!
>
>The image comes from a MySQL Blob. The closest I get is a string of garbage
>on the browser
>display.
>I cannot get it to display a pictures.
>
>Suggestions, comments, help, almost anything is appreciated. PLEASE help me!
>Project due in a week.
>
>Thanks in advance.
>
>Mike
>
>
> if( mysql_num_rows($result) == 1 )
> {
> //header('Content-type: image/*');
> $fileContent = mysql_result($result,0); //,$blobfield);
> echo $fileContent;
>
> //$theimage = imagecreatefromstring ($fileContent);
>
> //echo imagejpeg ( $theimage);
>
>
>
--
Experience is a good teacher, but she sends in terrific bills.
Minna Antrim
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
I've found a book that might help... "PHP graphics Handbook" from Wrox.
The example they have to get an image from a MySQL table is as follows:
after a successful query...
$buffer = stripslashes(mysql_result($result,0,0);
header("Content-type: image/jpg");
echo $buffer;
... and then close the database connection and other tidying up tasks...
As I said it's straight from the book, so I hope it helps!
graeme
MikeA wrote:
I had tried that once but then I was requested the download the file. But I gave your suggestion a
shot and I am getting an error message saying there is an error in the JPG file.
BTW, looking back at my original post I accidentally left out how I was calling the function. I used
this first.
<img src="get_image('sub','s_sub_code', $row['s_sub_code'], 's_map')">
Then I tried
get_image('sub','s_sub_code', $row['s_sub_code'], 's_map');
But I get that error in JPG message each time. So I am getting a little more closer. Here is how
the function looks now. The things I tried are commented out so I won't forget what I did.
function get_image($table, $pk_name, $pk_value, $blobfield)
{
login();
$query = 'SELECT '.$blobfield;
$query .= ' FROM '.$table;
$query .= ' WHERE '.$pk_name." = '".$pk_value."'";
//echo "<P>q=".$query."<P>";
$result = mysql_query( $query ) or die ("<P>Could not get image<P>");
if(mysql_num_rows($result) == 1 )
{
header('Content-type: image/jpeg');
//header('Content-type: image/*');
$fileContent = mysql_result($result,0); //,$blobfield);
$theimage = imagecreatefromstring ($fileContent);
echo imagejpeg ($theimage);
//echo $fileContent;
//header('Content-type: ' . image_type_to_mime_type(IMAGETYPE_WBMP));
//image2wbmp($image); // output the stream directly
}
But I am trying to put it in a table in the browser. If I can get the JPG to at least show up I
should be able to adjust it using a STYLE setting or TABLE. It is just getting it to output that has
got me stumped so far.
Thanks every so much for your help so far. Hope you can find the rest of it.
Thanks.
Mike
"graeme" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
Sorry running from memory here. You need to set your output headers to
display a jpg not text. So you need something like:
header("Content-type: image/jpg");
This will display the image on its own, if you need to embed the image
in a web page you need a little more trickery. I'll try to look it up
for you. But this should at least get you going on testing getting your
image from the database.
graeme
MikeA wrote:
I am trying to output a JPG image to the browser without creating a file. I
have tried several
things but nothing seems to work. I sure could use a whole lot of help right
now! LOL Going crazy
trying to figure this out. But I know there are PHP gurus out there that will
have the answer in 2
seconds. Hopefully I'll be at that level someday too!
The image comes from a MySQL Blob. The closest I get is a string of garbage on the browser
display.
I cannot get it to display a pictures.
Suggestions, comments, help, almost anything is appreciated. PLEASE help me!
Project due in a week.
Thanks in advance.
Mike
if( mysql_num_rows($result) == 1 )
{
//header('Content-type: image/*');
$fileContent = mysql_result($result,0); //,$blobfield);
echo $fileContent;
//$theimage = imagecreatefromstring ($fileContent);
//echo imagejpeg ( $theimage);
--
Experience is a good teacher, but she sends in terrific bills.
Minna Antrim
--- End Message ---
--- Begin Message ---
Patrick Roane wrote:
I am tring to store and display the number of requests
that a user has submitted via a hidden field. I've
created a form that does a some simple addtion.
Everything works, but I need some direction as to how
I can store each number the user puts in and to
display them.
Please see below:
<?php
if ( ! isset( $_POST['number1'] ['number2'] ) ) {
$message = "Welcome to the numbers game!";
}
$number1 = (int) $_POST['number1'];
$number2 = (int) $_POST['number2'];
$result = (int) $number1 + $number2;
$num_selections = (int) $POST['num_selections'];
$num_selections++; // this is my attempt at collecting
This will only store the num_selections for *this request*. Each time
you submit a form, it is a new request. To store information over
requests most people would use session variables:
http://www.php.net/manual/en/ref.session.php
--
Teach a person to fish...
Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
PHP Manual: http://www.php.net/manual/en/index.php
php-general archives: http://marc.theaimsgroup.com/?l=php-general&w=2
--- End Message ---
--- Begin Message ---
Thanks-
I will look into session vars.
--- Jason Barnett <[EMAIL PROTECTED]> wrote:
> Patrick Roane wrote:
> > I am tring to store and display the number of
> requests
> > that a user has submitted via a hidden field. I've
> > created a form that does a some simple addtion.
> > Everything works, but I need some direction as to
> how
> > I can store each number the user puts in and to
> > display them.
> > Please see below:
> >
> > <?php
> > if ( ! isset( $_POST['number1'] ['number2'] ) ) {
> > $message = "Welcome to the numbers game!";
> >
> > }
> > $number1 = (int) $_POST['number1'];
> > $number2 = (int) $_POST['number2'];
> > $result = (int) $number1 + $number2;
> >
> > $num_selections = (int) $POST['num_selections'];
> > $num_selections++; // this is my attempt at
> collecting
>
> This will only store the num_selections for *this
> request*. Each time
> you submit a form, it is a new request. To store
> information over
> requests most people would use session variables:
>
> http://www.php.net/manual/en/ref.session.php
>
>
> --
> Teach a person to fish...
>
> Ask smart questions:
> http://www.catb.org/~esr/faqs/smart-questions.html
> PHP Manual: http://www.php.net/manual/en/index.php
> php-general archives:
> http://marc.theaimsgroup.com/?l=php-general&w=2
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
=====
----------------
"forget your lust for the rich man's gold. All that you need, is in your soul.
You can do this if you try. All that I want for you my son, is to be satisfied"
~ Lynard Skynard
--- End Message ---
--- Begin Message ---
I created a form that asks for the users 1st and last
name. I than try and attempt to save this data to a
file. Next, I'd like to read the data from this file
and write its contents to the browser.
I only get so far before I get a wierd response after
hitting the submit button:
Resource id #3
See code below:
<?php
$firstnm = $_POST['firstnm']; //creates 1st var
$lastnm = $_POST['lastnm']; //create 2nd var
$filename = "names.txt"; //creates file to write the
//above variable values to
print "writing to $names.txt";
$fp = fopen( "names.txt", "w" ) or die("couldn't open
$names"); //opens the file I created
fwrite( $fp, "$firstnm\n" , "$lastnm"); //I don't know
//if this is right, but I attempt to write the
//variables to the file //here.
fclose( $fp ); //close the file
print "$fp_names"; //attempt to print the files
//contents to the browser here- but it does not work
$contents = file_get_contents( "names.txt" );
//attempts to read from file
print "$contents"; //attempts to display contents to
//browser
?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict/EN"
"http://www/w3/org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>form</title>
</head>
<body>
<h1>
<?php print "$fp" ?>
</h1>
<form method="post" action="<?php print
$_SERVER['PHP_SELF']?>">
<p>
Type your 1st name here: <input type="text"
name="firstnm" /><br />
Type your last name here: <input type="text"
name="lastnm" /><br />
<p><input type="submit" value="submit" /></p>
</p>
</form>
</body>
</html>
=====
----------------
"forget your lust for the rich man's gold. All that you need, is in your soul.
You can do this if you try. All that I want for you my son, is to be satisfied"
~ Lynard Skynard
--- End Message ---
--- Begin Message ---
Here are a few steps to try:
Go to your favourite text editor and open the file, what do you see?
If the contents are there then go back to your script and read the file
using *file_get_contents(filename)*
graeme
Patrick Roane wrote:
I created a form that asks for the users 1st and last
name. I than try and attempt to save this data to a
file. Next, I'd like to read the data from this file
and write its contents to the browser.
I only get so far before I get a wierd response after
hitting the submit button:
Resource id #3
See code below:
<?php
$firstnm = $_POST['firstnm']; //creates 1st var
$lastnm = $_POST['lastnm']; //create 2nd var
$filename = "names.txt"; //creates file to write the
//above variable values to
print "writing to $names.txt";
$fp = fopen( "names.txt", "w" ) or die("couldn't open
$names"); //opens the file I created
fwrite( $fp, "$firstnm\n" , "$lastnm"); //I don't know
//if this is right, but I attempt to write the
//variables to the file //here.
fclose( $fp ); //close the file
print "$fp_names"; //attempt to print the files
//contents to the browser here- but it does not work
$contents = file_get_contents( "names.txt" );
//attempts to read from file
print "$contents"; //attempts to display contents to
//browser
?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict/EN"
"http://www/w3/org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>form</title>
</head>
<body>
<h1>
<?php print "$fp" ?>
</h1>
<form method="post" action="<?php print
$_SERVER['PHP_SELF']?>">
<p>
Type your 1st name here: <input type="text"
name="firstnm" /><br />
Type your last name here: <input type="text"
name="lastnm" /><br />
<p><input type="submit" value="submit" /></p>
</p>
</form>
</body>
</html>
=====
----------------
"forget your lust for the rich man's gold. All that you need, is in your soul. You
can do this if you try. All that I want for you my son, is to be satisfied"
~ Lynard Skynard
--
Experience is a good teacher, but she sends in terrific bills.
Minna Antrim
--- End Message ---
--- Begin Message ---
If you note in my text I had said number. 5.7 is a number. If you want
to convert the number to an integer then there are a number of php
functions to do that. It all depends on how you want the conversion to
be done but a type cast (int) will eventually be necessary.
graeme
BENJAMIN LAMBE wrote:
dont mean to be padantic, but 5.7 is not an integer :p
lol
-----Original Message-----
From: graeme <[EMAIL PROTECTED]>
To: Louis Young <[EMAIL PROTECTED]>
Date: Mon, 17 Jan 2005 13:47:49 +0600
Subject: Re: [PHP-WIN] Newbie question: convert string to int
If you are holding a string with a valid number in it e.g. "5.7" then
the conversion is done automatically. See the manual section Language
Reference / Types / Strings / String conversion to numbers. If you are
holding a string with the number in words e.g. "Five" then you'll need
to write your own function for that.
graeme
Louis Young wrote:
Hi there
What's the function to convert a string to an int.
Cheers
Louis
--
Experience is a good teacher, but she sends in terrific bills.
Minna Antrim
--- End Message ---
--- Begin Message ---
Hi
Is there a tool that can do this for me, or do I have to do it manually?
Cheers
Louis
--- End Message ---
--- Begin Message ---
Hello Everyone,
I have (finally) had the time to build a version of the mssql extension
that uses FreeTDS on Win32. This should end some of the limitations in
Microsofts libraries (ie char/varchar with max width of 255 bytes). It
still ned some testing so if you are interested in testing this new
extension you can download it from http://kromann.info/php5.php. So far
its only available for the Release_TS build but the others will follow
soon.
The dll is called php_freetds.dll. You will also need to download
sybdb.dll. Later on I'll create a statically linked version.
- Frank
--- End Message ---
--- Begin Message ---
I am in the process of doing a small mailing list script. Does anyone have
any ideas an a SMTP server i can install under 98SE that is free and works i
can not seem to find one and my ISP will not allow me to use it without
loggin in first
Dean "The Insane Guy" Hayes
<-- I design and i redesign but still i never designed true beauty like you
-->
~~~ Call me Insane call me Crazy but there is one thing i know i am That is
someone that shall reach peoples hearts with words ~~~
~~ PHP seems easy enough but what about this ASP now that looks hard ~~
--- End Message ---
--- Begin Message ---
Hello php-windows,
On 18 January 2005, at 16:45:31 +1000 (which was 06:45 where I live) Dean
Hayes on php-windows wrote (and possibly edited)
> I am in the process of doing a small mailing list script. Does anyone have
> any ideas an a SMTP server i can install under 98SE that is free and works i
> can not seem to find one and my ISP will not allow me to use it without
> loggin in first
Try http://www.pmail.com/overviews/ovw_mercury.htm
--
Thanks, _______________________________________________
David | David Elliott | Software Engineer |
_________________________| [EMAIL PROTECTED] | PGP Key ID 0x650F4534 |
| Rejection: When imaginary beings won't talk to you. |
--- End Message ---
--- Begin Message ---
Hi All,
I am getting *Cannot open 'c:\PHP\extra\browscap.ini' for reading* on a
Windows 2003/IIS setup with PHP. Can anyone help out? Seems like a
pretty known error coz many links were found while Googling.
Thanks.
Hassan
--- End Message ---
--- Begin Message ---
Hi Guys
I tried using COM to connect to Excel, but this didn't work, so I'm
using PEAR now, but now there's another issue. I'm trying to connect to
an ActiveX component and having trouble again.
The following line of code:
$DelphiASPObj =& new COM("ClientBalance.coClientBalance") or Die("Did
not connect");
produces: Did not connect.
Cheers
Louis
--- End Message ---
--- Begin Message ---
I'm creating a survey, and i have a list of countries in a combo box to
be selected, is there way to find out from which country the client is
accessing the survey so i can pre select the country without him/her
having to select it...
Thx guys :)
Zu3Bi
--- End Message ---
--- Begin Message ---
Hi Guys
I'm trying to execute an MSSQL 2000 stored proc in PHP:
This:
$sp_FINGPDebtorBalance_query=mssql_query($_GLOBALS["GPDB"] .
"sp_FINGPDebtorBalance_rset '" . trim($Outlet_session) . "E', 0");
produces the following:
*Warning*: mssql_query(): Query failed in *c:\program files\apache
group\apache\htdocs\spar\admin\rpt_electrans.php* on line *172
If I echo the parameter of mssql_query and copy and paste it into SQL
Query Analyzer it works fine.
Any ideas what I might be missing?
Cheers
Louis
*
--- End Message ---