Page 1 of 1

form select

Posted: Wed Jun 18, 2003 3:25 pm
by stc7outlaw
I am making a program that lets users upload files to certain directories based on the certain option they pick. I want directories to be made automatically before the person even picks where they want the images to go. I did this as follows. *description first:($project_id specifies the MAIN folder--inputted by user-- and the corrosponding $sectiondir's are the subdirectory of the file which are chosen in the form select. There are 7 formselects. New Subdirectories are made for each Project ID directory. Bare with me, heh. :)

Code: Select all

<?php
$project_dir = $_POST['project_dir'];

function make_default_dirs() {

    global $project_dir;

   //create dirs
    mkdir("$project_dir/$sectiondir1/", 0755);
    chmod("$project_dir/$sectiondir1/", 0777);

    mkdir("$project_dir/$sectiondir2/", 0755);
    chmod("$project_dir/$sectiondir2/", 0777);

    mkdir("$project_dir/$sectiondir3/", 0755);
    chmod("$project_dir/$sectiondir3/", 0777);

    mkdir("$project_dir/$sectiondir4/", 0755);
    chmod("$project_dir/$sectiondir4/", 0777);

    mkdir("$project_dir/$sectiondir5/", 0755);
    chmod("$project_dir/$sectiondir5/", 0777);

    mkdir("$project_dir/$sectiondir6/", 0755);
    chmod("$project_dir/$sectiondir6/", 0777);
    
    mkdir("$project_dir/$sectiondir7/", 0755);
    chmod("$project_dir/$sectiondir7/", 0777);
}
if (!empty($_POST['project_dir']) ) {
  //check if main dir is available then makes if if it is not.
   mkdir("$project_dir/", 0755); 
   chmod("$project_dir/", 0777);
} else {
  print "Project photos'' directory not created";
}
if (is_dir("$project_dir/")  && !empty($_POST['project_dir']) ) {
   
   make_default_dirs();//execute function
} else {
   print "Please Enter a project id.";
}
?>
That was the easy part understanding the creating of the directories.:)

Now I would like to use a form select to specify which sectiondir it goes in but I dont want to have to use the hardcoded thing that I had above. 1 of the 7 form selects is as follows:

Code: Select all

&lt;select size="1" name="sectiondir1"&gt;
          &lt;OPTION&gt;-----Section-----
          &lt;OPTION VALUE="electricalpanel"&gt;Electrical Panel
          &lt;OPTION VALUE="contactor"&gt;Contactor Box
          &lt;OPTION VALUE="elements"&gt;Elements
          &lt;OPTION VALUE="steamtablewp"&gt;Steam Table Water Pans
          &lt;OPTION VALUE="steamcabwp"&gt;Steam Cabinet Water Pans
          &lt;OPTION VALUE="steamcabd"&gt;Steam Cabinet Doors
          &lt;OPTION VALUE="steamcabmod"&gt;Steam Cabinet Module
          &lt;OPTION VALUE="steamcabhe"&gt;Steam Cabinet Hood/Exhaust
          &lt;OPTION VALUE="producebin"&gt;Produce Bin
          &lt;OPTION VALUE="reachfridge"&gt;Reach in Refridgerator
          &lt;OPTION VALUE="panfillsys"&gt;Water Pan Water Fill System
          &lt;OPTION VALUE="steamtablecont"&gt;Steam Table Controller
          &lt;OPTION VALUE="tacowarmunit"&gt;Taco Warmer Unit/Taco Tower
          &lt;OPTION VALUE="cheesemelter"&gt;Round Up Cheese Melters
          &lt;OPTION VALUE="integrity"&gt;Structural Integrity
          &lt;OPTION VALUE="misc"&gt;Miscellaneous
          &lt;OPTION VALUE="summary"&gt;Summary/Recommendation
        
          &lt;/select&gt;
Is it possible to have arrays that I can use to choose which directory the image file goes by using the form select? I cant seem to find out how to do this anywhere.
Thanks a lot,
-Steve

Posted: Wed Jun 18, 2003 5:06 pm
by Galahad
I think this is what you are looking for. First, set up $uploaddir to be the proper folder based on the selection:

Code: Select all

<?php
$uploaddir = $project_dir;
$uploaddir = $uploaddir."/".$_POST['sectiondir1'];
?>
You can replace $project_dir with a literal string, if you want. You probably also want to make sure that $_POST['sectiondir1'] doesn't include any "." or "/" characters. That would prevent someone from trying to upload to any location they want to.

When you call move_uploaded_file, do something like this:

Code: Select all

<?php
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])
?>
Hope that helps.

Posted: Wed Jun 18, 2003 6:11 pm
by stc7outlaw
Well,
I already have that stuff, but I would like to put the sectiondir into an array that I can use instead of using that sectiondir1, sectiondir2, etc. Is it possible to have an array inside and array.

Posted: Thu Jun 19, 2003 3:04 am
by releasedj
Do you want the sub directories to have the same names as the <select> options?

Do you have more than 1 project that the user will chose?