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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:55:55+00:00 2026-05-16T15:55:55+00:00

$result = validateUploadedFile($_FILES); if (!empty($result) && !empty($result[‘valid’]) && $result[‘valid’]) { // do sth //

  • 0

$result = validateUploadedFile($_FILES);

if (!empty($result) && !empty($result['valid']) && $result['valid'])
{
    // do sth
    // I don't know why sometime this three checks will cause me problems
    // In other words, even if $result['valid'] is TRUE, this scope will not be hit
}

The function validateUploadedFile returns an array as $result[‘valid’] == TRUE if it goes through.

Here is the question, does the if statement checks too much?
Can I simply check the following instead? I have few PHP language knowledge and don’t know whether those checks are necessary or not.

if ( $result['valid'] )
{
    // do sth
}

Thank you

function validateUploadedFile($uploadedFile)
{
    // Define file size limit
    $result = array('valid' => FALSE, 'error_message' => null, 'error_code' => null);

    if (sth_wrong)
    {
      $result['error_message'] = 'sth_wrong';
      return $result;    
    }

    if (sth_wrong2)
    {
      $result['error_message'] = 'sth_wrong2';
      return $result;    
    }    

    $result['valid'] = TRUE;
    return $result;
}
  • 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-16T15:55:56+00:00Added an answer on May 16, 2026 at 3:55 pm

    It depends on what the function returns in the case where the uploaded file is not valid. This should probably suffice in most cases though:

    if (!empty($result['valid']))
    

    Since:

    • FALSE is empty
    • NULL (or an unset array index) is empty
    • It won’t complain, even if $result is an empty array

    You could also just do

    if (!$result['valid'])
    

    but this will give you E_NOTICE if that element isn’t set.

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

Sidebar

Related Questions

... // result is a JSON data passed to this function from outside var
I have the result of one API (FourSquare) giving me this.. [[4e01728f814d9dac7d52b93d,Bark Boutique,40.7143528,-74.0059731],[4d9f92dfaffda35d5db2a748,Bark Boutique,40.7143528,-74.0059731]]
result = tts.setLanguage(Locale.CHINA); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e(TTS, This
Result ( data ) looks like this: <tr> <td> Something... </td> </tr> <div id=paging>1,
The result set I'm speaking of this: http://docs.oracle.com/javase/1.4.2/docs/api/java/sql/ResultSet.html What I would like to do
FMOD_RESULT result; FMOD::System *system; result = FMOD::System_Create(&system); if (result != FMOD_OK) { printf(FMOD error!
DialogResult result; result = MessageBox.Show(breakpl[0], Move this to confige file?, MessageBoxButtons.YesNo); All I want
The result of Build and Analyze Showing me this line. Potential leak of an
the result of reponse is like this HTTP/1.1 200 OK Date: Fri, 11 Feb
TypeError: Result of expression 'this._configure' [undefined] is not a function. I keep running into

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.