sqlite3 - Calling variable from PHP Switch -
i can upload document onto main testing directory. wish call out variable staffno , place in specific staffno directory. i'm not able parse out variable though have declared appropriate name 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 not able call out though under form already. did did wrong somewhere? , wanted create new folder staffno if it's not found inside. basic staffno variable unable call out. kindly advise.
i have fixed several errors in upload.php have submitted. need assign value of hidden field variable: $staffno = $_post['staffno'];
upload.php
switch($_post['submit']) { case 'submit': if ($_files["upload"]["error"] > 0) { echo "error: " . $_files["upload"]["error"] . "<br />"; } else { $staffno = $_post['staffno']; // preform validation here echo "upload: " . $_files["upload"]["name"] . "<br />"; echo "type: " . $_files["upload"]["type"] . "<br />"; echo "stored in: " . $_files["upload"]["tmp_name"]; // check if directory exists if(!is_dir("documents/".$staffno)){ // if doesn't - create mkdir("documents/".$staffno); } 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; }
you should validate staffno
prevent changing value through firebug example, , messing upload path.
Comments
Post a Comment