Question : Variable not getting through POST

Good Afternoon,

I've got a file upload script (from one of the more esteemed experts of this site), but am having trouble getting the variable to display after the POST.  $userfile is the name of the variable that I'd like to display after the POST.

HELP and THANKS!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
echo "<center><table width=\"300\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">";
		echo "<tr><td align=\"center\"><img src=\"images/title_meetingminsadd.jpg\"  /><br /><br /></td></tr></table>";
		
		if (isset($_POST['Submit'])){
		
		$userfile = $_POST['userfile'];
		echo $userfile;

			

			{
			
			
			foreach ($_FILES as $my_uploaded_file)
			
    {
	


// SKIP OVER EMPTY SPOTS - NOTHING UPLOADED
        $error_code    = $my_uploaded_file["error"];
        if ($error_code == 4) continue;

// SYNTHESIZE THE NEW FILE NAME
        $f_type    = trim(strtolower(end    (explode( '.', basename($my_uploaded_file['name'] )))));
        $f_name    = trim(strtolower(current(explode( '.', basename($my_uploaded_file['name'] )))));
		$length = 35;
		$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
		$string = $f_name;    
		for ($p = 0; $p < $length; $p++) {
			$f_name1 .= $characters[mt_rand(0, strlen($characters))];
		}
    		
		$my_new_file = $uploads . '/' . $f_name1 .'.'. $f_type;
        $my_file     = $uploads . '/' . $f_name1 .'.'. $f_type;


// OPTIONAL TEST FOR ALLOWABLE EXTENSIONS
        if (!in_array($f_type, $file_exts)) die("<div class=\"maintext\">Sorry, $f_type files not allowed</div>");

// IF THERE ARE ERRORS
        if ($error_code != 0)
        {
            $error_message = $errors[$error_code];
            die("<div class=\"maintext\">Sorry, Upload Error Code: $error_code: $error_message</div>");
        }

// GET THE FILE SIZE
        $file_size    = number_format($my_uploaded_file["size"]);

// MOVE THE FILE INTO THE DIRECTORY
// IF THE FILE IS NEW
        if (!file_exists($my_new_file))
        {
            if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
            {
                $upload_success = 1;
            }
            else
            {
                $upload_success = -1;
            }

// IF THE FILE ALREADY EXISTS
        }
        else
        {
            echo "<br/><div class=\"maintext\"><b><i>$my_file</i></b> already exists.</div>\n";

// SHOULD WE OVERWRITE THE FILE? IF NOT
            if (empty($_POST["overwrite"]))
            {
                $upload_success = 0;

// IF WE SHOULD OVERWRITE THE FILE, TRY TO MAKE A BACKUP
            }
            else
            {
                $now    = date('Y-m-d');
                $my_bak = $my_new_file . '.' . $now . '.bak';
                if (!copy($my_new_file, $my_bak))
                {
                    echo "<br/><div class=\"maintext\"><b>Attempted Backup Failed!</b></div>\n";
                }
                if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
                {
                    $upload_success = 2;
                }
                else
                {
                    $upload_success = -1;
                }
            }
        }

// REPORT OUR SUCCESS OR FAILURE
        if ($upload_success == 2) { echo "<br/><div class=\"maintext\">It has been overwritten.</div>\n"; }
        if ($upload_success == 1) { echo "<br/><div class=\"maintext\">File has been uploaded.</div>\n"; }
        if ($upload_success == 0) { echo "<br/><div class=\"maintext\"><b>It was NOT overwritten.</b></div>\n"; }
        if ($upload_success < 0)  { echo "<br/><div class=\"maintext\"><b>ERROR <i>$my_file</i> NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND</b></div>\n"; }
        if ($upload_success > 0)
        {
            echo "<br />";
			$filename = $f_name1 .'.'. $f_type;
			$_SESSION['filename'] = $filename;
			
			echo "<br /><input type=\"submit\" value=\"Continue to Step 2\" onClick=\"location.href='meeting-minutes-add-step2.php'\"><br /><br />";
					
			echo "<br /><br />";
            if (!chmod ($my_new_file, 0755))
            {
                echo "<br/>chmod(0755) FAILED: fileperms() = ";
                echo substr(sprintf('%o', fileperms($my_new_file)), -4);
            }
            
        }
// END ITERATOR
    }
	
	}
			
       } //end if yes for post


			
			
			
			
			
			else
				{
				
	
			////////////////////////////////////////////////////////////////
			echo "<table width=\"350\" cellpadding=\"2\" cellspacing=\"2\">";		
		echo "<tr align=\"left\"><td>";
		echo "<div class=\"maintexterror\">Only .PDF, .DOC, and .DOCX files can be uploaded.</div><br />";
		echo "<div class=\"maintext\">Click the \"Browse\" button to find the file you want to upload.  After the file has been selected, click the \"Upload\" button below.</div><br />";
		echo "</td></tr></table>";
		
		echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" enctype=\"multipart/form-data\" name=\"UploadForm\">\n";
			?>
			
    <input type="hidden" name="MAX_FILE_SIZE" value="<?=$max_file_size?>" />
	<?php
	


     for ($n = 0; $n < $nf; $n++)
        {
            echo "<input name=\"userfile\" type=\"file\" size=\"40\" /><br/>\n";
        }
    echo "<br /><br /><input value=\"0\" type=\"hidden\" name=\"overwrite\" /><input type=\"submit\" name=\"Submit\" value=\"Upload File\" />";
	?>
    </form>
	<?php
	
				 echo "<br /><br /><div class=\"maintext\"><a onclick=\"parent.parent.location.href='meeting-minutes-management.php';return false;\" href=\"javascript:;\" name=\"propr\">Close Window</a></div></center>";
				 

        }

Answer : Variable not getting through POST

Just Change

$userfile = $_POST['userfile'];

to

$userfile = $_FILES['userfile']['name'];
Random Solutions  
 
programming4us programming4us