I can upload my document onto my main testing directory. But I wish to call out my variable which is staffNo and place it in the specific staffNo directory. But I’m not able to parse out the variable even though I have declared my appropriate name for my input.
For example:
Staff Page
$staffNo = 1;
<form id="Staff" name="Staff" method="post" action="upload.php" enctype="multipart/form-data">
//My staffno variable
<input type="hidden" id="staffNo" name="staffNo" value="<?php echo $staffNo ?>"/>
//Upload document
<input name="upload" id="upload" type="file"/>
<input type="hidden" name="upload" value="upload"/>
//Submit button
<input type="submit" name="submit" value="Submit">
</form>
upload.php
switch($_POST['submit'])
{
case 'Submit':
if ($_FILES["upload"]["error"] > 0)
{
echo "Error: " . $_FILES["upload"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["upload"]["name"] . "<br />";
echo "Type: " . $_FILES["upload"]["type"] . "<br />";
echo "Stored in: " . $_FILES["upload"]["tmp_name"];
move_uploaded_file($_FILES["upload"]["tmp_name"],
"documents/"."staffNo"."/".$_FILES["upload"]["name"]);
echo "Stored in: " ."./documents/"."staffNo"."/". $_FILES["upload"]["name"];
}
break;
case 'others':
break;
default;
My staffNo variable was not able to call out even though it is under the form already. Did I did wrong somewhere? And I also wanted to create a new folder for the staffNo if it’s not found inside. But now the basic staffNo variable was unable to call out. Kindly advise.
I have fixed several errors in upload.php you have submitted.
You need to assign value of the hidden field to a variable:
$staffNo = $_POST['staffNo'];upload.php
You should probably validate
staffNoto prevent changing its value through firebug for example, and messing with the upload path.