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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:50:48+00:00 2026-06-10T06:50:48+00:00

I post an image url to a php script. In this php script I

  • 0

I post an image url to a php script. In this php script I get the image url and check what the extension is and if this extension matches a couple of extensions or not:

        $ext1 = pathinfo($_POST['form_pic'], PATHINFO_EXTENSION);
        $ext = strtolower($ext1);

        if($ext != 'jpg' || $ext != 'jpeg' || $ext != 'png' || $ext != 'gif') {
            echo $ext; echo "wrong";        
        }else{
            echo "a correct extension";
        }

But even when I a post an url like: http://www.test.com/picture.jpg and he gets the extension, in this case jpg, he still goes through the if statement, saying the extension is not equal to the one mentioned in the if statement.

I don’t know what I am doing wrong?

  • 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-10T06:50:49+00:00Added an answer on June 10, 2026 at 6:50 am

    Your code is almost right but you have to use correct operator which is && in this case.

    Please try this:

    $ext1 = pathinfo($_POST['form_pic'], PATHINFO_EXTENSION);
    $ext = strtolower($ext1);
    
       if($ext != 'jpg' && $ext != 'jpeg' && $ext != 'png' && $ext != 'gif') {
            echo $ext; echo "wrong";        
       } else {
            echo "A correct extension";
       }
    

    When you a use a sequence of negative statements there always should be used operator &&.

    There are a lot of ways to do what you want but if you want to keep your code as it is just change || to && and you will be fine.

    Please read more about Logical Operators in PHP.

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

Sidebar

Related Questions

I have this script: var wall_user_id = <?php echo $_SESSION['user_id'];?>; $.ajax({ type: POST, url:
Using Jquery AJAX to get a value from a PHP script. This line works
I have this image proxy. It worked fine in PHP 4 but not that
$page = $curl->post($baseUrl.'/submit.php', array('url'=>$address,'phase'=>'1','randkey'=>$randKey[0],'id'=>'c_1')); $exp = explode('recaptcha_image',$page); The id recaptcha_image is not found although
I'm using simple_html_dom.php to get all images from an url (like pinterest does) if($_POST['submit'])
I am trying to receive the url image and post the image into base64
This question is related to my previous post Image Processing Algorithm in Matlab in
http://demo.thethemefoundry.com/traction/#post-183 Which wordpress plugin is this, to have post image on the left side
I made a script to post comments on a page. I have used PHP
I'm using TinyMCE and want to execute a php script get the output and

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.