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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:05:53+00:00 2026-06-08T16:05:53+00:00

I have PHP form where a user can upload an image. I check this

  • 0

I have PHP form where a user can upload an image. I check this form for several other problems like empty fields and every problem gets their own error message. If there is more than one error, de form doesn’t send the data and the user sees an error message. So far, so good! Now I want to show an error message when the image isn’t a PNG, JPG or GIF or is larger than 250k. I’ve written a code, that doesn’t seem to do anything! I can leave the entire form blank and set a .MP3 as ‘file to upload’, all the error messages appear, excep the one for the image. What’s going wrong? Here is my code:

$aErrors = array();

$filecheck = basename($_FILES['bedrijfslogo']['name']);
$ext = strtolower(substr($filecheck, strrpos($filecheck, '.') + 1));

if (!(($ext != "jpg" && $ext != "gif" && $ext != "png") || ($_FILES["bedrijfslogo"]["type"] != "image/jpeg" && $_FILES["bedrijfslogo"]["type"] != "image/gif" && $_FILES["bedrijfslogo"]["type"] != "image/png") ||    ($_FILES["bedrijfslogo"]["size"] > 250000))){

    $aErrors['bedrijfslogo'] = 'Uw bedrijfslogo is te groot of niet het juiste formaat';
  }

And the code inside the HTMl form :

<tr>
<td class="first">Bedrijfslogo:</td>
<td><input tabindex="8" type="file" name="bedrijfslogo" value="<?php echo isset($_POST['bedrijfslogo'])?$_POST['bedrijfslogo']:""; ?>" class="wizardinput" style="background-color:white;"></td>
</tr>

What’s going wrong guys? Big thanks in advance!

  • 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-08T16:05:54+00:00Added an answer on June 8, 2026 at 4:05 pm

    Your logic is a little confusing

    if (!(($ext != "jpg" && $ext != "gif" && $ext != "png") || ($_FILES["bedrijfslogo"]["type"] != "image/jpeg" && $_FILES["bedrijfslogo"]["type"] != "image/gif" && $_FILES["bedrijfslogo"]["type"] != "image/png") ||    ($_FILES["bedrijfslogo"]["size"] > 250000))){
        $aErrors['bedrijfslogo'] = 'Uw bedrijfslogo is te groot of niet het juiste formaat';
    }
    

    Try simplifying it

    if (!preg_match("/^jpg|gif|png$/", $ext) || !preg_match("/^image\/(jpeg|gif)$/", $_files["bedrijfslogo"]["type"]) || $_FILES["bedrijfslogo"]["size"] > 250000) {
        //code here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a form in which user can upload 100 mb file which results
I have a form where user can upload audio file (mp3), but instead of
I have a upload field where people can upload a image. I'd like to
I have a form which upload a big file to server. Something like this:
I have a form where users can upload an image. I have another page
I have created a PHP form which requires the user to select a postcode
I have a PHP form with 4 text fields and 2 checkboxes. The checkboxes
I have a basic PHP form (a few fields and 2 checkboxes, I want
I have a html/php form like the following: Form 1: Apple options: -big -medium
I'm implementing an upload form so that my users can upload a background image

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.