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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:11:05+00:00 2026-06-17T20:11:05+00:00

How can I upload txt, doc/docx, ppt/pptx, pdf and restrict all other file types

  • 0

How can I upload txt, doc/docx, ppt/pptx, pdf and restrict all other file types while uploading file using php and jquery? Can i do it with jQuery also?

I have tried this.

$allowedExts = array("doc", "docx", "pdf", "txt");
$extension = end(explode(".", $_FILES["file"]["name"]));
if (($_FILES["file"]["type"] == "application/msword")
|| ($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "application/txt") 
&& in_array($extension, $allowedExts)){}

I need it in JQuery or a better way in PHP.

  • 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-17T20:11:06+00:00Added an answer on June 17, 2026 at 8:11 pm

    Try this using php :

    $fileTypes = array('txt','doc','docx','ppt','pptx','pdf'); // file extensions allowed
    $fileParts = pathinfo($_FILES['file']['name']);
    
    if(in_array($fileParts['extension'],$fileTypes))
    {
       // upload file here if the extension matches to your allowed ones.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Paperclip / S3 for file uploading. I upload text-like files (not .txt,
I need to allow the user to upload only text files(.txt,.doc,.rtf etc). How can
In our application, we allow user to upload documents which can be PDF, Doc,
I have a form where the user can upload a zip file, it works
I have a page where a user can upload a file along with some
I can upload file into database (mysql). When i try to upload same file
i have a form in which user can upload 100 mb file which results
here is a site http://www.lyrkjsw.gov.cn that can let the registered user to upload file
I have a fileupload function where users can upload files. I want to restrict
This is what I'm trying to do : Download a file (txt, doc, xls,

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.