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 8256873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:00:41+00:00 2026-06-08T02:00:41+00:00

I am using the HTML form below to pass a file to PHP for

  • 0

I am using the HTML form below to pass a file to PHP for handling. But PHP says that the index is undefined.

Also, similarly, a variable I defined in config.php is showing as undefined.

What am I missing here?

classes.php

<?php
require('config.php');
error_reporting(E_ALL);
/*
 * Classes required by the script
 * 
 */

class database extends PDO
{
    public $conURL;

    public function __construct($config) {
        $conURL = "mysql:host=" . $config['host'] . ";dbname=" . $config['db'];
        try {
         parent::__construct($conURL, $config['user'], $config['pass']);
        } catch (PDOException $e) {
            $e->getMessage();
        }
    }       
}

class upload
{
    public $_FILES;

    public function uploadFile() {
        if ($_FILES['file']['size'] >= 2000000) {
           echo "File is too large!";
        }
        elseif (isset($_FILES['file'])) {
           $stmt = $this->prepare("INSERT INTO upload (name, type, size, content) VALUES (?, ?, ?, ?)");
           $stmt->execute(array($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $_FILES['file']['file']));
        }
    }
}

config.php

<?php
$config = array(
        'host' => 'localhost', // db host
        'user' => 'root', // db user
        'pass' => 'mypassword', //db pass
        'db' => 'files' // db name
);

upload.php

<?php
error_reporting(E_ALL);
require('config.php');
require('classes.php');

$dbh = new database($config);
$upload = new upload();
$upload->uploadFile();

HTML form

<form name="uploaddb" action="upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
<input type="file" name="file" />
<br/>
<input type="submit" name="submit" value="Upload!" />
</form>

And for reference, here are the errors:

Notice: Undefined variable: config in
/Applications/MAMP/htdocs/files/classes.php on line 28

Notice: Undefined index: file in
/Applications/MAMP/htdocs/files/classes.php on line 34

  • 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-08T02:00:43+00:00Added an answer on June 8, 2026 at 2:00 am

    I didn’t test it, but here is what I think is wrong:

    1. Do not require config.php on the class files. You are already passing $config to the database constructor.
    2. Do not declare $_FILES on your classes, it’s a superglobal available everywhere.

    I’d also recommend you capitalize your class names.

    UPDATE

    Sorry that I can’t put it all together right now. Here is a couple more problems I see:

    1. There’s no file key on $_FILES['file']. Not sure which key you’re looking for.
    2. You can’t use db methods on class upload as it is now. Isn’t $this->prepare causing an error? That class does not extend PDO. Maybe you should have the upload method inside the db class.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using an html file like below (tv.html): <form action=myaspx.aspx?appid=5018 method=post id=formSubscription name=formSubscription> <input
I'm trying to update a database using html form + jquery + php When
I am using an html form that submits data to a MYSQL database. I
Hey, I'm using a html form that is used to log people into my
When ever I pass a value from a form using submit to a php
below is my simple code using HTML 5 multiple file upload. All i need
I have a form like below:- <% using ( Html.BeginForm(search, home, FormMethod.Get) ) {
Just what the question title says. I'm using SpringMVC, but that's irrelevant really. I
Below is the code that I am using with Jquery to pass a value
I'm working on a signup form using jQuery's AJAX and Codeigniter PHP framework, but

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.