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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:39:50+00:00 2026-05-21T08:39:50+00:00

On my site I have a page where users can upload files to go

  • 0

On my site I have a page where users can upload files to go with the news post they’re adding. I allow them to upload one image and one sound file. They don’t have to add files if they don’t want to, or they can just add one if they want. Problem I’m having is that my script only works if the user selects both files. If they choose none, or only one, then the script spits out ‘Invalid File’ as it can’t find a file where one hasn’t been selected.

I tried using:

if (isset($_FILES['filetoupload1'])) { 
    if (($_FILES["filetoupload1"]["type"] == "image/gif")
        || ($_FILES["filetoupload1"]["type"] == "image/jpeg")
        || ($_FILES["filetoupload1"]["type"] == "image/pjpeg")
        || ($_FILES["filetoupload1"]["type"] == "image/png")
        || ($_FILES["filetoupload1"]["type"] == "image/jpg")
    ) {
        if ($_FILES["filetoupload1"]["error"] > 0) {
            echo "Return Code: " . $_FILES["filetoupload1"]["error"] . "<br />";
        } else {
        if (file_exists("media/" . $_FILES["filetoupload1"]["name"])) {
                echo $_FILES["filetoupload1"]["name"] . " already exists. ";
            }
            move_uploaded_file(
                $_FILES["filetoupload1"]["tmp_name"],
                "media/" . $_FILES["filetoupload1"]["name"]
            );
        }
    } else {
        echo "Invalid file";
    }
}


if (isset($_FILES['filetoupload2'])) { 
    if ($_FILES["filetoupload2"]["type"] == "audio/mp3") {
        if ($_FILES["filetoupload2"]["error"] > 0) {
            echo "Return Code: " . $_FILES["filetoupload2"]["error"] . "<br />";
        } else {
        if (file_exists("media/" . $_FILES["filetoupload2"]["name"])) {
                echo $_FILES["filetoupload2"]["name"] . " already exists. ";
            }
            move_uploaded_file(
                $_FILES["filetoupload2"]["tmp_name"],
                "media/" . $_FILES["filetoupload2"]["name"]
            );
        }
    } else {
        echo "Invalid file";
    }
}

and then

if((isset($_FILES['filetoupload1'])) && (isset($_FILES['filetoupload2']))) { }

before both first and second upload scripts if the user had selected both image and audio file. In other words it did this:

if filetoupload1 isset then run upload script that filters images.
if filetoupload2 isset then run upload script that filters audio.
if filetoupload1 AND filetoupload2 isset then run both upload scripts.

I have it set like that. The above should allow for all combinations of file uploads. right? but it doesnt work so..

Now I have no idea what to do. Here’s the upload script for the audio, the image one is pretty much the same:

Can someone tell me what I’m doing wrong please!

  • 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-21T08:39:50+00:00Added an answer on May 21, 2026 at 8:39 am

    “I get the error: Invalid file”

    This is correct, since your code just does this.
    Do not check if the file is set but if i.e. $_FILES["filetoupload1"]["type"] is not empty.

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

Sidebar

Related Questions

I have created a page on my site where users can post directly to
I have a site where users upload content and they can name what they
I have an upload page in django powered site. The end-users upload the documents
I have it so that users can copy and paste objects from one page
I have a page on my site where a user can upload a Photoshop,
I have a page where a user can import data to the site. either
i have a search page in my site, where user can search all the
I have a page on my site that lets users respond to invites by
I have a members site where users are given up to 7 web page
I have a list of individual redirects that move users (and google) from abc.site.com/page/name

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.