FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » echo other way to output a constant?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
echo other way to output a constant? [message #169476] Tue, 14 September 2010 22:12 Go to next message
MikeB is currently offline  MikeB
Messages: 65
Registered: September 2010
Karma: 0
Member
Say I have the following code:

<?php


define('MAX_FILE_SIZE', 300);

echo <<<_END
<html><head><title>PHP Form Upload</title></head><body>
<form method='post' action='UploadFile2.php' enctype='multipart/form-data'>
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="" />
Select a JPG, GIF, PNG or TIF File:
<input type='file' name='filename' size='60' />
<br/><input type='submit' value='Upload' /></form>
_END;

echo "</body></html>";
?>

How can I get PHP to place the value of the constant MAX_FILE_SIZE in
the value attribute for the hidden field MAX_FILE_SIZE?

Since it does not start with a $-sign it is not interpreted as a
variable. I tried putting it in curly braces {}, which sometimes work,
but that didn't do the trick either.

I was hoping that print_r() would do it, but I could not get PHP to
interpret that either.

So any way or do I have to a) put the constant in a variable or b) echo
each line individually so that I can do concatenation of the output lines?

Thanks.
Re: echo other way to output a constant? [message #169482 is a reply to message #169476] Wed, 15 September 2010 01:25 Go to previous messageGo to next message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma: 0
Senior Member
On Tue, 14 Sep 2010 17:12:38 -0500, MikeB wrote:
> Say I have the following code:
>
> <?php
>
>
> define('MAX_FILE_SIZE', 300);
>
> echo <<<_END
> <html><head><title>PHP Form Upload</title></head><body>
> <form method='post' action='UploadFile2.php' enctype='multipart/form-data'>
> <!-- MAX_FILE_SIZE must precede the file input field -->
> <input type="hidden" name="MAX_FILE_SIZE" value="" />
> Select a JPG, GIF, PNG or TIF File:
> <input type='file' name='filename' size='60' />
> <br/><input type='submit' value='Upload' /></form>
> _END;
>
> echo "</body></html>";
> ?>
>
> How can I get PHP to place the value of the constant MAX_FILE_SIZE in
> the value attribute for the hidden field MAX_FILE_SIZE?
>
> Since it does not start with a $-sign it is not interpreted as a
> variable. I tried putting it in curly braces {}, which sometimes work,
> but that didn't do the trick either.
>
> I was hoping that print_r() would do it, but I could not get PHP to
> interpret that either.
>
> So any way or do I have to a) put the constant in a variable or b) echo
> each line individually so that I can do concatenation of the output lines?

PHP puts responses to forms sent using method post into a special array
called "_POST". So, to get at the contents of an input control called
"MAX_FILE_SIZE", you use the variable $_POST['MAX_FILE_SIZE']. There is
some trickiness with input types that can return multiple values, but we
can get to that once you've gotten the above bits working and are
comfortable with them.

--
The Write Many, Read Never drive. For those people that don't know
their system has a /dev/null already.
-- Rik Steenwinkel, singing the praises of 8mm Exabytes
Re: echo other way to output a constant? [message #169484 is a reply to message #169476] Wed, 15 September 2010 01:45 Go to previous messageGo to next message
rf is currently offline  rf
Messages: 19
Registered: September 2010
Karma: 0
Junior Member
"MikeB" <mpbrede(at)gmail(dot)com> wrote in message
news:4c8ff366(at)news(dot)x-privat(dot)org...
> Say I have the following code:
>
> <?php
>
>
> define('MAX_FILE_SIZE', 300);
>
> echo <<<_END
> <html><head><title>PHP Form Upload</title></head><body>
> <form method='post' action='UploadFile2.php'
> enctype='multipart/form-data'>
> <!-- MAX_FILE_SIZE must precede the file input field -->
> <input type="hidden" name="MAX_FILE_SIZE" value="" />
> Select a JPG, GIF, PNG or TIF File:
> <input type='file' name='filename' size='60' />
> <br/><input type='submit' value='Upload' /></form>
> _END;
>
> echo "</body></html>";
> ?>
>
> How can I get PHP to place the value of the constant MAX_FILE_SIZE in the
> value attribute for the hidden field MAX_FILE_SIZE?
>
> Since it does not start with a $-sign it is not interpreted as a variable.
> I tried putting it in curly braces {}, which sometimes work, but that
> didn't do the trick either.

All of this is mentioned in the manual.

echo <<<_END
<html><head><title>PHP Form Upload</title></head><body>
<form method='post' action='UploadFile2.php' enctype='multipart/form-data'>
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="
_END;

echo MAX_FILE_SIZE;

echo <<<_END
" />
Select a JPG, GIF, PNG or TIF File:
<input type='file' name='filename' size='60' />
<br/><input type='submit' value='Upload' /></form>
_END;
Re: echo other way to output a constant? [message #169486 is a reply to message #169482] Wed, 15 September 2010 01:52 Go to previous messageGo to next message
MikeB is currently offline  MikeB
Messages: 65
Registered: September 2010
Karma: 0
Member
Peter H. Coffin wrote:
> On Tue, 14 Sep 2010 17:12:38 -0500, MikeB wrote:
>> Say I have the following code:
>>
>> <?php
>>
>>
>> define('MAX_FILE_SIZE', 300);
>>
>> echo<<<_END
>> <html><head><title>PHP Form Upload</title></head><body>
>> <form method='post' action='UploadFile2.php' enctype='multipart/form-data'>
>> <!-- MAX_FILE_SIZE must precede the file input field -->
>> <input type="hidden" name="MAX_FILE_SIZE" value="" />
>> Select a JPG, GIF, PNG or TIF File:
>> <input type='file' name='filename' size='60' />
>> <br/><input type='submit' value='Upload' /></form>
>> _END;
>>
>> echo "</body></html>";
>> ?>
>>
>> How can I get PHP to place the value of the constant MAX_FILE_SIZE in
>> the value attribute for the hidden field MAX_FILE_SIZE?
>>
>> Since it does not start with a $-sign it is not interpreted as a
>> variable. I tried putting it in curly braces {}, which sometimes work,
>> but that didn't do the trick either.
>>
>> I was hoping that print_r() would do it, but I could not get PHP to
>> interpret that either.
>>
>> So any way or do I have to a) put the constant in a variable or b) echo
>> each line individually so that I can do concatenation of the output lines?
>
> PHP puts responses to forms sent using method post into a special array
> called "_POST". So, to get at the contents of an input control called
> "MAX_FILE_SIZE", you use the variable $_POST['MAX_FILE_SIZE']. There is
> some trickiness with input types that can return multiple values, but we
> can get to that once you've gotten the above bits working and are
> comfortable with them.
>
Perhaps I expressed myself poorly.

I want PHP to send html to the browser.

It should look like this:

<input type="hidden" name="MAX_FILE_SIZE" value="300" />

This is as part of an echo <<<_END statement.

The number 300 in the above instance is a constant in my PHP code
defined as:

define('MAX_FILE_SIZE', 300);

If I try to put the following in my program, the literal MAX_FILE_SIZE
appears in the html:

echo <<<_END
<input type="hidden" name="MAX_FILE_SIZE" value="MAX_FILE_SIZE" />
_END

if I do this, I get what I want:

$mfs = MAX_FILE_SIZE;
echo <<<_END
<input type="hidden" name="MAX_FILE_SIZE" value="$mfs" />
_END

So are you saying that an alternate method is to initialize the
MAX_FILE_SIZE element in the _POST array and do it that way?

Thanks.
Re: echo other way to output a constant? [message #169488 is a reply to message #169476] Wed, 15 September 2010 07:00 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On 14/09/10 23:12, MikeB wrote:
> Say I have the following code:
>
> <?php
>
>
> define('MAX_FILE_SIZE', 300);
>
> echo <<<_END
> <html><head><title>PHP Form Upload</title></head><body>
> <form method='post' action='UploadFile2.php' enctype='multipart/form-data'>
> <!-- MAX_FILE_SIZE must precede the file input field -->
> <input type="hidden" name="MAX_FILE_SIZE" value="" />
> Select a JPG, GIF, PNG or TIF File:
> <input type='file' name='filename' size='60' />
> <br/><input type='submit' value='Upload' /></form>
> _END;
>
> echo "</body></html>";
> ?>
>
> How can I get PHP to place the value of the constant MAX_FILE_SIZE in
> the value attribute for the hidden field MAX_FILE_SIZE?

Observation - you have a string literal that happens to be a constant
name, or a constant name that is also a string literal. Scope for confusion.

define ('_MAXFILESIZE',300);

then either:

$mfs = _MAXFILESIZE;
echo <<<_END
<html><head><title>PHP Form Upload</title></head><body>
<form method='post' action='UploadFile2.php' enctype='multipart/form-data'>
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="$mfs" />
Select a JPG, GIF, PNG or TIF File:
<input type='file' name='filename' size='60' />
<br/><input type='submit' value='Upload' /></form>
_END;

or:

echo <<<_END
<html><head><title>PHP Form Upload</title></head><body>
<form method='post' action='UploadFile2.php' enctype='multipart/form-data'>
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="
_END;
echo _MAXFILESIZE;
echo <<<_END
" />
Select a JPG, GIF, PNG or TIF File:
<input type='file' name='filename' size='60' />
<br/><input type='submit' value='Upload' /></form>
_END;

Rgds

Denis McMahon
Re: echo other way to output a constant? [message #169500 is a reply to message #169486] Wed, 15 September 2010 15:25 Go to previous messageGo to next message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma: 0
Senior Member
On Tue, 14 Sep 2010 20:52:31 -0500, MikeB wrote:
> Peter H. Coffin wrote:
>> On Tue, 14 Sep 2010 17:12:38 -0500, MikeB wrote:
>>> Say I have the following code:
>>>
>>> <?php
>>>
>>>
>>> define('MAX_FILE_SIZE', 300);
>>>
>>> echo<<<_END
>>> <html><head><title>PHP Form Upload</title></head><body>
>>> <form method='post' action='UploadFile2.php' enctype='multipart/form-data'>
>>> <!-- MAX_FILE_SIZE must precede the file input field -->
>>> <input type="hidden" name="MAX_FILE_SIZE" value="" />
>>> Select a JPG, GIF, PNG or TIF File:
>>> <input type='file' name='filename' size='60' />
>>> <br/><input type='submit' value='Upload' /></form>
>>> _END;
>>>
>>> echo "</body></html>";
>>> ?>
>>>
>>> How can I get PHP to place the value of the constant MAX_FILE_SIZE in
>>> the value attribute for the hidden field MAX_FILE_SIZE?
>>>
>>> Since it does not start with a $-sign it is not interpreted as a
>>> variable. I tried putting it in curly braces {}, which sometimes work,
>>> but that didn't do the trick either.
>>>
>>> I was hoping that print_r() would do it, but I could not get PHP to
>>> interpret that either.
>>>
>>> So any way or do I have to a) put the constant in a variable or b) echo
>>> each line individually so that I can do concatenation of the output lines?
>>
>> PHP puts responses to forms sent using method post into a special array
>> called "_POST". So, to get at the contents of an input control called
>> "MAX_FILE_SIZE", you use the variable $_POST['MAX_FILE_SIZE']. There is
>> some trickiness with input types that can return multiple values, but we
>> can get to that once you've gotten the above bits working and are
>> comfortable with them.
>>
> Perhaps I expressed myself poorly.

Or perhaps I read poorly.

> I want PHP to send html to the browser.
>
> It should look like this:
>
> <input type="hidden" name="MAX_FILE_SIZE" value="300" />
>
> This is as part of an echo <<<_END statement.
>
> The number 300 in the above instance is a constant in my PHP code
> defined as:
>
> define('MAX_FILE_SIZE', 300);
>
> If I try to put the following in my program, the literal MAX_FILE_SIZE
> appears in the html:
>
> echo <<<_END
> <input type="hidden" name="MAX_FILE_SIZE" value="MAX_FILE_SIZE" />
> _END
>
> if I do this, I get what I want:
>
> $mfs = MAX_FILE_SIZE;
> echo <<<_END
> <input type="hidden" name="MAX_FILE_SIZE" value="$mfs" />
> _END
>
> So are you saying that an alternate method is to initialize the
> MAX_FILE_SIZE element in the _POST array and do it that way?
>
> Thanks.

No, but I don't think you can do variable or constant expansion inside a
heredoc, the thing with the <<< operation. You can terminate it early,
before the part that you want to contain the variable, print a bit that
includes the variable expansion, then do more heredoc dumping. Thusly:

<?php


$MAX_FILE_SIZE=300;

echo<<<_END
<html><head><title>PHP Form Upload</title></head><body>
<form method='post' action='UploadFile2.php'
enctype='multipart/form-data'>
<!-- MAX_FILE_SIZE must precede the file input field -->
_END;
print "<input type='hidden' name='$MAX_FILE_SIZE' value='' />";
echo<<<_END
Select a JPG, GIF, PNG or TIF File:
<input type='file' name='filename' size='60' />
<br/><input type='submit' value='Upload' /></form>
_END;

echo "</body></html>";
?>

As far as I can remember, heredocs do zero procession on the output
aside from checking for line-ending-followed-by-end-tag. Which means
you can potentially be bitten by line ending problems, character set
problems, etc, etc.

--
_ o
|/)
Re: echo other way to output a constant? [message #169501 is a reply to message #169476] Wed, 15 September 2010 15:44 Go to previous messageGo to next message
Gordon[1] is currently offline  Gordon[1]
Messages: 6
Registered: September 2010
Karma: 0
Junior Member
On Sep 14, 11:12 pm, MikeB <mpbr...@gmail.com> wrote:
> Say I have the following code:
>
> <?php
>
> define('MAX_FILE_SIZE', 300);
>
> echo <<<_END
> <html><head><title>PHP Form Upload</title></head><body>
> <form method='post' action='UploadFile2.php' enctype='multipart/form-data'>
> <!-- MAX_FILE_SIZE must precede the file input field -->
> <input type="hidden" name="MAX_FILE_SIZE" value="" />
> Select a JPG, GIF, PNG or TIF File:
> <input type='file' name='filename' size='60' />
> <br/><input type='submit' value='Upload' /></form>
> _END;
>
> echo "</body></html>";
> ?>
>
> How can I get PHP to place the value of the constant MAX_FILE_SIZE in
> the value attribute for the hidden field MAX_FILE_SIZE?
>
> Since it does not start with a $-sign it is not interpreted as a
> variable. I tried putting it in curly braces {}, which sometimes work,
> but that didn't do the trick  either.
>
> I was hoping that print_r() would do it, but I could not get PHP to
> interpret that either.
>
> So any way or do I have to a) put the constant in a variable or b) echo
> each line individually so that I can do concatenation of the output lines?
>
> Thanks.

Doing it this way is making your life harder than it needs to be. A
better approach would be to have a page of basically standard HTML
markup and using PHP to inject the values into that.

The way I'd do it would be to have a PHP file that does all your
business logic, and at its last line does an include () of another PHP
file that defines how the output should be presented to the users.

Using this approach, you'd end up with something more along these
lines:

(businesslogic.php)

<?php

define ('MAX_FILE_SIZE', 300);

/**
* The rest of your business logic goes here. Store anything you want
* to use on your page into a variable
*/

include ('page.php');
?>

(page.php)

<html><head><title>PHP Form Upload</title></head><body>
<form method='post' action='UploadFile2.php' enctype='multipart/form-
data'>
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo
(MAX_FILE_SIZE); ?>" />
Select a JPG, GIF, PNG or TIF File:
<input type='file' name='filename' size='60' />
<br/><input type='submit' value='Upload' /></form>
</body></html>

Hope you can understand what's going on here.
Re: echo other way to output a constant? [message #169502 is a reply to message #169500] Wed, 15 September 2010 15:57 Go to previous messageGo to next message
matt[1] is currently offline  matt[1]
Messages: 40
Registered: September 2010
Karma: 0
Member
On Sep 15, 11:25 am, "Peter H. Coffin" <hell...@ninehells.com> wrote:
> On Tue, 14 Sep 2010 20:52:31 -0500, MikeB wrote:
>> Peter H. Coffin wrote:
>>> On Tue, 14 Sep 2010 17:12:38 -0500, MikeB wrote:
>>>> Say I have the following code:
>
>>>> <?php
>
>>>> define('MAX_FILE_SIZE', 300);
>
>>>> echo<<<_END
>>>> <html><head><title>PHP Form Upload</title></head><body>
>>>> <form method='post' action='UploadFile2.php' enctype='multipart/form-data'>
>>>> <!-- MAX_FILE_SIZE must precede the file input field -->
>>>> <input type="hidden" name="MAX_FILE_SIZE" value="" />
>>>> Select a JPG, GIF, PNG or TIF File:
>>>> <input type='file' name='filename' size='60' />
>>>> <br/><input type='submit' value='Upload' /></form>
>>>> _END;
>
>>>> echo "</body></html>";
>>>> ?>
>
>>>> How can I get PHP to place the value of the constant MAX_FILE_SIZE in
>>>> the value attribute for the hidden field MAX_FILE_SIZE?
>
>>>> Since it does not start with a $-sign it is not interpreted as a
>>>> variable. I tried putting it in curly braces {}, which sometimes work,
>>>> but that didn't do the trick  either.
>
>>>> I was hoping that print_r() would do it, but I could not get PHP to
>>>> interpret that either.
>
>>>> So any way or do I have to a) put the constant in a variable or b) echo
>>>> each line individually so that I can do concatenation of the output lines?
>
>>> PHP puts responses to forms sent using method post into a special array
>>> called "_POST". So, to get at the contents of an input control called
>>> "MAX_FILE_SIZE", you use the variable $_POST['MAX_FILE_SIZE']. There is
>>> some trickiness with input types that can return multiple values, but we
>>> can get to that once you've gotten the above bits working and are
>>> comfortable with them.
>
>> Perhaps I expressed myself poorly.
>
> Or perhaps I read poorly.
>
>
>
>> I want PHP to send html to the browser.
>
>> It should look like this:
>
>> <input type="hidden" name="MAX_FILE_SIZE" value="300" />
>
>> This is as part of an echo <<<_END statement.
>
>> The number 300 in the above instance is a constant in my PHP code
>> defined as:
>
>> define('MAX_FILE_SIZE', 300);
>
>> If I try to put the following in my program, the literal MAX_FILE_SIZE
>> appears in the html:
>
>> echo <<<_END
>> <input type="hidden" name="MAX_FILE_SIZE" value="MAX_FILE_SIZE" />
>> _END
>
>> if I do this, I get what I want:
>
>> $mfs = MAX_FILE_SIZE;
>> echo <<<_END
>> <input type="hidden" name="MAX_FILE_SIZE" value="$mfs" />
>> _END
>
>> So are you saying that an alternate method is to initialize the
>> MAX_FILE_SIZE element in the _POST array and do it that way?
>
>> Thanks.
>
> No, but I don't think you can do variable or constant expansion inside a
> heredoc, the thing with the <<< operation. You can terminate it early,
> before the part that you want to contain the variable, print a bit that
> includes the variable expansion, then do more heredoc dumping. Thusly:
>
> <?php
>
> $MAX_FILE_SIZE=300;
>
> echo<<<_END
> <html><head><title>PHP Form Upload</title></head><body>
> <form method='post' action='UploadFile2.php'
> enctype='multipart/form-data'>
> <!-- MAX_FILE_SIZE must precede the file input field -->
> _END;
> print "<input type='hidden' name='$MAX_FILE_SIZE' value='' />";
> echo<<<_END
> Select a JPG, GIF, PNG or TIF File:
> <input type='file' name='filename' size='60' />
> <br/><input type='submit' value='Upload' /></form>
> _END;
>
> echo "</body></html>";
> ?>

No, PHP won't extrapolate a defined constant in heredoc syntax,
anymore than it would in a regular string:

define("MY_CONSTANT", 4);
echo "MY_CONSTANT";

But, it will work just fine if you use a regular variable:

$MY_CONSTANT = 4;
echo <<<END
$MY_CONSTANT
END;

It has nothing to do with heredoc and everything to do with PHP's
string parsing. heredoc and double quoted strings behave exactly the
same in this capacity.

Personally, I'd love to see the complex syntax expanded to retrieve
constants as such:

echo "{MY_CONSTANT}";

> As far as I can remember, heredocs do zero procession on the output
> aside from checking for line-ending-followed-by-end-tag. Which means
> you can potentially be bitten by line ending problems, character set
> problems, etc, etc.

You're not quite right on the heredoc parsing. I have gotten bitten
before when Windows style line endings have crept into code, however
to me that's more of a problem with repository control than the
heredoc syntax. You'd have the same problem if you were writing a
command line utility with a she-bang at the top.

more here: http://www.php.net/manual/en/language.types.string.php
Re: echo other way to output a constant? [message #169503 is a reply to message #169501] Wed, 15 September 2010 16:27 Go to previous messageGo to next message
MikeB is currently offline  MikeB
Messages: 65
Registered: September 2010
Karma: 0
Member
Gordon wrote:

> Doing it this way is making your life harder than it needs to be. A
> better approach would be to have a page of basically standard HTML
> markup and using PHP to inject the values into that.
>
> The way I'd do it would be to have a PHP file that does all your
> business logic, and at its last line does an include () of another PHP
> file that defines how the output should be presented to the users.
>
> Using this approach, you'd end up with something more along these
> lines:
>
> (businesslogic.php)
>
> <?php
>
> define ('MAX_FILE_SIZE', 300);
>
> /**
> * The rest of your business logic goes here. Store anything you want
> * to use on your page into a variable
> */
>
> include ('page.php');
> ?>
>
> (page.php)
>
> <html><head><title>PHP Form Upload</title></head><body>
> <form method='post' action='UploadFile2.php' enctype='multipart/form-
> data'>
> <!-- MAX_FILE_SIZE must precede the file input field -->
> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo
> (MAX_FILE_SIZE); ?>" />
> Select a JPG, GIF, PNG or TIF File:
> <input type='file' name='filename' size='60' />
> <br/><input type='submit' value='Upload' /></form>
> </body></html>
>
> Hope you can understand what's going on here.

I think I understand, but I don't see how it's easier and I don't see
how you will expand that example to include the form processing without
making it more confusing than it seems to be.

But then I'm new at this, so perhaps I'm missing something?
Re: echo other way to output a constant? [message #169504 is a reply to message #169502] Wed, 15 September 2010 16:34 Go to previous messageGo to next message
MikeB is currently offline  MikeB
Messages: 65
Registered: September 2010
Karma: 0
Member
matt wrote:
You'd have the same problem if you were writing a
> command line utility with a she-bang at the top.
>

"she-bang?"

Oh nvm. Just don't Google it with Safe Search=Off. :(
Re: echo other way to output a constant? [message #169506 is a reply to message #169504] Wed, 15 September 2010 16:55 Go to previous messageGo to next message
matt[1] is currently offline  matt[1]
Messages: 40
Registered: September 2010
Karma: 0
Member
On Sep 15, 12:34 pm, MikeB <mpbr...@gmail.com> wrote:
> matt wrote:
>
>   You'd have the same problem if you were writing a
>
>> command line utility with a she-bang at the top.
>
> "she-bang?"
>
> Oh nvm. Just don't Google it with Safe Search=Off.  :(

ROFL! Somehow I never made that connection...
Re: echo other way to output a constant? [message #169507 is a reply to message #169488] Wed, 15 September 2010 18:20 Go to previous messageGo to next message
bobmct is currently offline  bobmct
Messages: 16
Registered: September 2010
Karma: 0
Junior Member
On Wed, 15 Sep 2010 08:00:06 +0100, Denis McMahon
<denis(dot)m(dot)f(dot)mcmahon(at)googlemail(dot)com> wrote:
> echo <<<_END
> <html><head><title>PHP Form Upload</title></head><body>
> <form method='post' action='UploadFile2.php' enctype='multipart/form-data'>
> <!-- MAX_FILE_SIZE must precede the file input field -->
> <input type="hidden" name="MAX_FILE_SIZE" value="
> _END;
> echo _MAXFILESIZE;
> echo <<<_END
> " />
> Select a JPG, GIF, PNG or TIF File:
> <input type='file' name='filename' size='60' />
> <br/><input type='submit' value='Upload' /></form>
> _END;
>
> Rgds
>
> Denis McMahon


How about something as simple as:

$MAX_FILE_SIZE = 300;

then in the html output:

<input type="hidden" name="MAX_FILE_SIZE" value="$MAX_FILE_SIZE">
Re: echo other way to output a constant? [message #169512 is a reply to message #169503] Thu, 16 September 2010 08:16 Go to previous messageGo to next message
Gordon[1] is currently offline  Gordon[1]
Messages: 6
Registered: September 2010
Karma: 0
Junior Member
On Sep 15, 5:27 pm, MikeB <mpbr...@gmail.com> wrote:
> Gordon wrote:
>> Doing it this way is making your life harder than it needs to be.  A
>> better approach would be to have a page of basically standard HTML
>> markup and using PHP to inject the values into that.
>
>> The way I'd do it would be to have a PHP file that does all your
>> business logic, and at its last line does an include () of another PHP
>> file that defines how the output should be presented to the users.
>
>> Using this approach, you'd end up with something more along these
>> lines:
>
>> (businesslogic.php)
>
>> <?php
>
>> define ('MAX_FILE_SIZE', 300);
>
>> /**
>>   * The rest of your business logic goes here. Store anything you want
>>   * to use on your page into a variable
>>   */
>
>> include ('page.php');
>> ?>
>
>> (page.php)
>
>> <html><head><title>PHP Form Upload</title></head><body>
>> <form method='post' action='UploadFile2.php' enctype='multipart/form-
>> data'>
>> <!-- MAX_FILE_SIZE must precede the file input field -->
>> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo
>> (MAX_FILE_SIZE); ?>" />
>> Select a JPG, GIF, PNG or TIF File:
>> <input type='file' name='filename' size='60' />
>> <br/><input type='submit' value='Upload' /></form>
>> </body></html>
>
>> Hope you can understand what's going on here.
>
> I think I understand, but I don't see how it's easier and I don't see
> how you will expand that example to include the form processing without
> making it more confusing than it seems to be.
>
> But then I'm new at this, so perhaps I'm missing something?

The advantage of this approach is that it introduces a separation
between business logic and presentation. If you intermingle these two
things then it makes life harder than necessary later down the line
when changes have to be made to either thing. You can even delegate
the presentation side of things to a web designer who doesn't know a
lot of PHP but can turn out really nice looking pages should you
wish :)
Re: echo other way to output a constant? [message #169514 is a reply to message #169506] Thu, 16 September 2010 10:55 Go to previous message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 15-09-10 18:55, matt wrote:
> On Sep 15, 12:34 pm, MikeB<mpbr...@gmail.com> wrote:
>> matt wrote:
>>
>> You'd have the same problem if you were writing a
>>
>>> command line utility with a she-bang at the top.
>>
>> "she-bang?"
>>
>> Oh nvm. Just don't Google it with Safe Search=Off. :(
>
> ROFL! Somehow I never made that connection...

a dirty mind, is a joy for ever....

--
Luuk
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Removing insignificant decimal characters?
Next Topic: Reference # in var_dump output?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 15:54:59 GMT 2024

Total time taken to generate the page: 0.02393 seconds