RE: [PHP] Directory to array to select box...
Since I ran this on Win2000 machine, I changed name of directory: You were right on the money with your code; just a minor mod or two was required: ?php $i=0; // counter $files = array(); // array to store directory content // open directory $dir = opendir(c:\\wbs\\); // loop through directory and put filenames into an array while ($filex = readdir($dir)) { $files[$i] = $filex; $i++; // pull $file (directory array into select box) $file_count .=OPTION VALUE=\$filex\$filex/OPTION\n; } $form = pFORM METHOD=\post\ ACTION=\blank.php3\\n. SELECT NAME=\files\$file_count/SELECT\n. INPUT TYPE=\submit\ NAME=\submit\ VALUE=\select\\n. /FORM/p; // close directory closedir($dir); print $form; ? outputs the following: pFORM METHOD=post ACTION=blank.php3 SELECT NAME=filesOPTION VALUE=../OPTION OPTION VALUE=/OPTION OPTION VALUE=activities.txtactivities.txt/OPTION OPTION VALUE=addwbs.php3addwbs.php3/OPTION OPTION VALUE=classWBS.phpclassWBS.php/OPTION OPTION VALUE=funcs.incfuncs.inc/OPTION OPTION VALUE=link.phplink.php/OPTION OPTION VALUE=snoopy.incsnoopy.inc/OPTION OPTION VALUE=wbs.sqlwbs.sql/OPTION OPTION VALUE=wbsconv.phpwbsconv.php/OPTION OPTION VALUE=wbsform.php3wbsform.php3/OPTION OPTION VALUE=wbsload.sqlwbsload.sql/OPTION OPTION VALUE=wbspkg.php3wbspkg.php3/OPTION OPTION VALUE=wbsproject.csvwbsproject.csv/OPTION OPTION VALUE=wbsproject.mppwbsproject.mpp/OPTION OPTION VALUE=xx.phpxx.php/OPTION /SELECT INPUT TYPE=submit NAME=submit VALUE=select /FORM/p -Original Message- From: Jas [mailto:[EMAIL PROTECTED]] Sent: Friday, April 05, 2002 9:33 AM To: [EMAIL PROTECTED] Subject: [PHP] Directory to array to select box... Ok here is my problem, for one I am new to php and would like a new pair of eyes for this piece of code, and second what I would like to accomplish is putting the contents of a directory into an array and then pulling the contents of that array into a select box for further processing... If someone could give me some more information on GetDirArray() or a different way to accomplish this problem that would be great... this is where I am thus far. ?php $i=0; // counter $files = array(); // array to store directory content // open directory $dir = opendir(/home/web/b/bignickel.net/htdocs/); // loop through directory and put filenames into an array while ($file = readdir($dir)) { $files[$i] = $file; $i++; } // pull $file (directory array into select box) $file_count .=OPTION VALUE=\$file\$file/OPTION; $form = pFORM METHOD=\post\ ACTION=\blank.php3\ SELECT NAME=\files\$file_count/SELECT INPUT TYPE=\submit\ NAME=\submit\ VALUE=\select\ /FORM/p; // close directory closedir($dir); ? Then of course I just use an echo to display the select box but so far I have not been able to have it actually work so any help would be great.. Thanks in advance, jas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Directory to array to select box...
Hey Rick, thanks a ton... you have helped me out alot on this list. I got the code working probably about the same time you and another gentleman posted the same fixes I made, however I now have another question about adding a hidden field to take the results of the users selection and passing it along to another form which will stick it into a database, not the file mind you, i simply need to stick the path of the file into a database table. If you have any suggestions on how to do this that would be great. Thanks again, Jas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Directory to array to select box...
I must be missing something. Just add a HIDDEN type in your form. It will be sent with all your form data. -Original Message- From: Jas [mailto:[EMAIL PROTECTED]] Sent: Friday, April 05, 2002 10:14 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] Directory to array to select box... Hey Rick, thanks a ton... you have helped me out alot on this list. I got the code working probably about the same time you and another gentleman posted the same fixes I made, however I now have another question about adding a hidden field to take the results of the users selection and passing it along to another form which will stick it into a database, not the file mind you, i simply need to stick the path of the file into a database table. If you have any suggestions on how to do this that would be great. Thanks again, Jas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Directory to array to select box...
So adding a hidden field would definately pass the contents of the select box to the other script so I am not doing anything wrong with this portion, but what if I wanted to append the path of the file name? Any tips? Thanks, jas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Directory to array to select box...
the contents of the SELECT box and the contents of the HIDDEN field are separate entities. Append the path upon transfer to the next PHP script Show us what you REALLY want to do here instead of keeping us guessing... -Original Message- From: Jas [mailto:[EMAIL PROTECTED]] Sent: Friday, April 05, 2002 10:22 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] Directory to array to select box... So adding a hidden field would definately pass the contents of the select box to the other script so I am not doing anything wrong with this portion, but what if I wanted to append the path of the file name? Any tips? Thanks, jas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Directory to array to select box...
Sorry, here is what I have thus far... everything is working except I am just not sure how to pass the result of the users selection to another script, I have added the hidden input type to try and solve it but I think I am doing something wrong, maybe I need to put the hidden input type on the second script to place the contents into the database, here is the code... ?php $dir_name = /path/to/directory/; $dir = opendir($dir_name); $file_list .= pFORM METHOD=\post\ ACTION=\ad_done.php3\ SELECT NAME=\files\$file_name; while ($file_name = readdir($dir)) { if (($file_name != .) ($file_name !=..)) { $file_list .= OPTION VALUE=\$file_name\$file_name/OPTION; } } // added hidden field here... and so far it is not getting any value, so i am assuming that i need it on my ad_done.php3 script??? $file_list .= INPUT TYPE=\hidden\ NAME=\$file_name\ VALUE=\$file_name\/SELECTbrbrINPUT TYPE=\submit\ NAME=\submit\ VALUE=\select\/FORM/p; closedir($dir); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Directory to array to select box...
When ad_done.php3 is called, it will receive a variable named $files. Change: SELECT NAME=\files\$file_name; to: SELECT NAME=\files\; $files will contain the value of the file selected -Original Message- From: Jas [mailto:[EMAIL PROTECTED]] Sent: Friday, April 05, 2002 10:36 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] Directory to array to select box... Sorry, here is what I have thus far... everything is working except I am just not sure how to pass the result of the users selection to another script, I have added the hidden input type to try and solve it but I think I am doing something wrong, maybe I need to put the hidden input type on the second script to place the contents into the database, here is the code... ?php $dir_name = /path/to/directory/; $dir = opendir($dir_name); $file_list .= pFORM METHOD=\post\ ACTION=\ad_done.php3\ SELECT NAME=\files\$file_name; while ($file_name = readdir($dir)) { if (($file_name != .) ($file_name !=..)) { $file_list .= OPTION VALUE=\$file_name\$file_name/OPTION; } } // added hidden field here... and so far it is not getting any value, so i am assuming that i need it on my ad_done.php3 script??? $file_list .= INPUT TYPE=\hidden\ NAME=\$file_name\ VALUE=\$file_name\/SELECTbrbrINPUT TYPE=\submit\ NAME=\submit\ VALUE=\select\/FORM/p; closedir($dir); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Directory to array to select box...
On Fri, 5 Apr 2002, Jas wrote: So adding a hidden field would definately pass the contents of the select box to the other script so I am not doing anything wrong with this portion, but what if I wanted to append the path of the file name? Any tips? This isn't an answer to your question, but I just wanted to warn you: If you place something like a path in a hidden field, or as part of a select option, you have no guarantee that a user won't change it before submitting the form. Most browsers won't let them, but there are plenty of other ways they can (for instance, debugging web proxies that allow editing of raw form submissions, and so on). So it's VERY IMPORTANT that you don't rely on this path without doing further checks to make sure it's really valid. Otherwise people could try to read or write any file on your system. They probably won't get away with writing directly, but if they manage to read your password file or something, they soon will be writing. miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php