Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8223753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:49:31+00:00 2026-06-07T14:49:31+00:00

I can upload my document onto my main testing directory. But I wish to

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:49:32+00:00Added an answer on June 7, 2026 at 2:49 pm

    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

    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 it doesn't - create it
                    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 probably validate staffNo to prevent changing its value through firebug for example, and messing with the upload path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A user can upload a picture on my site at which point jQuery inserts
As part of a web application users can upload files of data, which generates
It would appear that FileReference.upload() is the only way in which you can upload
I have a form which includes 3 textfields so users can upload files. They
I can upload documents into sharepoint via following code. My document library has 3
i can upload and download but the file that i download is corrupted. the
I need a simple library or tool with which I can upload arbitrary files
I want to write a web site which can edit OpenOffice document ODF, user
I am developing an upload script where you can upload an picture, which is
Situation Users can upload Documents, a queue message will be placed onto the queue

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.