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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:32:50+00:00 2026-05-29T04:32:50+00:00

Being a noob … I can’t quite figure out what isn’t working here ….

  • 0

Being a noob … I can’t quite figure out what isn’t working here ….
if the file is empty, $this->result contains the right error message.
But if I have a file name, the result array is empty and I’m not getting an upload

class upload_f
{
    public $path;              // path to upload from root ie  files/images/
    public $fileName;          // current file  ie $_FILES['uploadedfile']['name'];
    public $result = array();  // array containing error to be loop outside object

    public function validateInput()       // verify is minimal data is entered.
    {

        if (empty($this->fileName))
        {
            $this->result[] = "ERROR: File name is empty.";
            return false;
        }
    } // end of validate


    public function upload()
    {
        // run validation
        if (!$this->validateInput())
        {
            return $this->result;
        }
        else
        {
            $f_name = $this->fileName;
            $path_fileName = $this->path.$this->fileName;

            if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $path_fileName))
            {
                $this->result[] =
                    "File  ".  basename( $_FILES['uploadedfile']['name']). " was uploaded";
            }
            else
            {
                $this->result[] = "There was an error uploading the file, please try again!";
            }

            $this->result[] = $path_fileName;
            return  $this->result;

        } // end of else : upload execution if no errors
    }

} // end of upload class

[...]

//****************************************/

// call the object
// form here with a if - post ... 
$the_array = $test->upload();
$test = new upload_f();
// assgin values
$test->path = "docs/";
$test->fileName = $_FILES['uploadedfile']['name'];
$the_array = $test->upload();
echo "<pre>";
print_r ($the_array);
echo "</pre>";
  • 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-05-29T04:32:51+00:00Added an answer on May 29, 2026 at 4:32 am

    You should change validateInput() to:

    public function validateInput() {    
        if (empty($this->fileName)) {
            $this->result[] = "ERROR: File name is empty.";
            return false;
        }
        return true; // <-- return true if input is valid
    }
    

    As you have it, the method returns something falsy for all cases, causing !$this->validateInput() always to evaluate to true.

    Reference

    • Converting to boolean
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my code, I know there's a small mistake somewhere but being a noob
Sorry If I am being noob, I have this doubt, why do we use
this is a noob question but I cannot for the life of me figure
A relative noob to Python, I've successfully pulled a text file, out of a
Forgive me for being a noob, but shouldn't this work? $(document).ready(function() { $('.button').click(function() {
Can anyone explain how compilation works? I can't seem to figure out how compilation
XSL noob here :-) I've got the following template which is being used to
guys sorry for being so noob but im still starting yet with my php,
Being a relative submodules noob, I wanted to update my submodule with from its
Being new to test based development, this question has been bugging me. How much

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.