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

  • Home
  • SEARCH
  • 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 706235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:08:36+00:00 2026-05-14T04:08:36+00:00

Here is a code form a PHP+MySQL book I am reading and I am

  • 0

Here is a code form a PHP+MySQL book I am reading and I am having trouble understanding this code. This code is about checking a file uploaded into a database. (Please excuse any spelling errors if any, I was typing it in)

Q1: How does it know which case to echo? In the whole code, there is no mention of each case.

Q2: Why do they skip case 5?! Or does it not matter which numbers you use(so I can have case 1, case 18, case 2?)

For this statement, can you say if($_FILES[‘userfile’][‘error’]=1) instead of >0? Are they the same thing?

    if($_FILES['userfile']['error']>0)
{
    echo 'Problem: ';
switch($_FILES['userfile']['error'])
{
    case 1: echo 'File exceeded upload_max_filesize';
            break;
    case 2: echo 'File exceeded max_file_size';
            break;
    case 3: echo 'File only partially uploaded';
            break;
    case 4: echo 'No file uploaded';
            break;
    case 6: echo 'Cannot upload file: no temp directory specified';
            break;
    case 7: echo 'Upload failed: Cannot write to disk';
            break;
}
exit;
}
  • 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-14T04:08:37+00:00Added an answer on May 14, 2026 at 4:08 am

    This should help:

    UPLOAD_ERR_OK Value: 0; There is no
    error, the file uploaded with success.

    UPLOAD_ERR_INI_SIZE Value: 1; The
    uploaded file exceeds the
    upload_max_filesize directive in
    php.ini.

    UPLOAD_ERR_FORM_SIZE Value: 2; The
    uploaded file exceeds the
    MAX_FILE_SIZE directive that was
    specified in the HTML form.

    UPLOAD_ERR_PARTIAL Value: 3; The
    uploaded file was only partially
    uploaded.

    UPLOAD_ERR_NO_FILE Value: 4; No file
    was uploaded.

    UPLOAD_ERR_NO_TMP_DIR Value: 6;
    Missing a temporary folder. Introduced
    in PHP 4.3.10 and PHP 5.0.3.

    UPLOAD_ERR_CANT_WRITE Value: 7; Failed
    to write file to disk. Introduced in
    PHP 5.1.0.

    UPLOAD_ERR_EXTENSION Value: 8; A PHP
    extension stopped the file upload. PHP
    does not provide a way to ascertain
    which extension caused the file upload
    to stop; examining the list of loaded
    extensions with phpinfo() may help.
    Introduced in PHP 5.2.0.

    The gist of it is that when you are handling an uploaded file, you check the error value ($_FILES['userfile']['error']) to see the status of the file. The switch statement just breaks it down by checking the possible error codes that could be present. These are basically "hardwired".

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

Sidebar

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.