Re: echo other way to output a constant? [message #169488 is a reply to message #169476] |
Wed, 15 September 2010 07:00 |
Denis McMahon
Messages: 634 Registered: September 2010
Karma:
|
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
|
|
|