Re: echo other way to output a constant? [message #169501 is a reply to message #169476] |
Wed, 15 September 2010 15:44 |
Gordon[1]
Messages: 6 Registered: September 2010
Karma:
|
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.
|
|
|