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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:05:07+00:00 2026-05-26T12:05:07+00:00

I am trying out PHP my first actual script, most of it from tutorial

  • 0

I am trying out PHP my first actual script, most of it from tutorial 🙁
Anyway’s

I am having a problem on this part

// This is our limit file type condition
if (!($uploaded_type=="text/java")||!($uploaded_type=="file/class")||!($uploaded_type=="file/jar")) {
echo "You may only upload Java files.<br>";

$ok=0;
}

Basically it doesn’t allow any files, even those up there
help!
I want the Java files to be allowed only!

EDIT:
Here is the full code

<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$uploaded = basename( $_FILES['uploaded']['name']) ;
$ok=1;

//This is our size condition
if ($uploaded_size > 350000) {
    echo "Your file is too large.<br>";
    $ok=0;
}

// This is our limit file type condition
if (!($uploaded_type=="text/java")||!($uploaded_type=="file/class")||! ($uploaded_type=="file/jar")) {
    echo "You may only upload Java files.<br>";
    $ok=0;
}

echo $ok;  //Here we check that $ok was not set to 0 by an error
if ($ok==0) {
    echo "Sorry your file was not uploaded";
}else {
    if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
        echo "The file ". $uploaded ." has been uploaded";
    } else {
        echo "Sorry, there was a problem uploading your file.";
    }
}
?>
  • 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-26T12:05:08+00:00Added an answer on May 26, 2026 at 12:05 pm

    You’re using an OR… that means the whole statement evaluates as TRUE if ANY of its member arguments are true. Since a file can only be of one type, you’re excluding ALL files. What you want is an ‘and’ match:

    if (!($uploaded_type == 'text/java') && !($uploaded_type == ....)) {
                                         ^^---boolean and
    

    Pretending that we’re working with a file/class file type, then you version reads:

    if the (file is not text/java) OR the (file is not file/class) OR the (file is not file/jar)
                  TRUE                           FALSE                          TRUE
    
    TRUE or FALSE or TRUE -> TRUE
    

    Switchign to AND gives you

    TRUE and FALSE and TRUE -> FALSE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying out PDO in PHP for the first time. I thought that
I am trying to call a function in another .php file from this one
I am trying to find out how to merge the FIPS part of this
Trying out some things with php and html, I'm having issues trying to get
I'm working on a PHP CMS like project and I'm trying to find out
While trying out an experimental UINavigationController-based iPhone application, I ran into a problem when
Just trying out Hibernate (with Annotations) and I'm having problems with my mappings. I
I'm trying out the following query: SELECT A,B,C FROM table WHERE field LIKE 'query%'
I'm trying out ASP.NET MVC routing and have of course stumbled across a problem.
First of all, I'm new to Java. I'm trying to figure out what would

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.