getting variable name from the variable itself?
You are talking about variable variables, getting a variable from a string.
I want it the opposite way, getting a string from a variable.
But have been more or less convinced that it can't be done.
/Ludde
Quote:
> > >... but the varname isn't printed neither.
> > Which suggests that even the php guys don't know how to do that ;)
> I'm not sure if I'm following this right, but here's how I used
> variable variable names for my application (online real estate
> listings). I have a page that presents a form allowing the user to
> upload a PDF brochure by selecting up to eight PDF files (pages 1 - 8)
> and then clicking on upload. So, I have a do loop in PHP that spits
> out the input form fields using variable variable names thusly:
> <?
> // this generates eight input fields named page1 - page8
> $page_num = 1;
> while ($page_num <= $MAX_PDF_PAGES) //defined within PHP file as 8
> {
> $input_name = "page" . $page_num;
> ?>
> <input type=file size=48 name=<?= $input_name ?>
> accept="image/gif,jpg,jpeg" value="">
> <?
> ++page_num;
> }
> ?>
> The form action invokes another php file that loops through the inputs
> to see which ones were specified - which had files uploaded to them.
> This is still in the test stage, so it prints out the information, ...
> like so:
> $page_num = 1;
> while ($page_num <= $MAX_PDF_PAGES) // = 8
> {
> $input_name = "page" . $page_num;
> print "$input_name = ";
> print "${$input_name} <br>"; // variable variable name
> // check to see if this page was uploaded - note the "varibale
> variable" name
> if (isset(${$input_name}) && ${$input_name} != "none")
> {
> $pdf_fname = $page_num . ".pdf";
> $fpath = '../pdfs/' . $pdf_fname;
> //move uploaded file
> if (!move_uploaded_file($HTTP_POST_FILES[$input_name][tmp_name],
> "$fpath"))
> {
> echo "Possible file upload attack. Filename: ${$input_name}";
> die();
> }
> }
> ++$page_num;
> }
> --
> **********************************************
> Chuck Anderson . Boulder, CO CycleTourist at
> http://www.CycleTourist.com attbi.com
> Tolerance is recognizing that other people have different ideals
> and needs than you. Compromise is acting on that knowledge.
> ***********************************************************