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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:24:43+00:00 2026-05-23T07:24:43+00:00

How do I set the form restrictions in php to only allow jpgs and

  • 0

How do I set the form restrictions in php to only allow jpgs and pdfs for upload? Also, I seem to have an upload error when I set the file size to 800000. Here is the upload form:

<form action="upload_files.php" method="post"
enctype="multipart/form-data">
<label for="img_preview">Preview Image:</label>
<input type="file" name="img_preview" id="img_preview" />
<br />
<label for="pdf_doc">Your PDF:</label>
<input type="file" name="pdf_doc" id="pdf_doc" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

Here is the upload_files.php

<?php
if ((($_FILES["img_preview"]["type"] == "image/gif")
|| ($_FILES["img_preview"]["type"] == "image/jpeg")
|| ($_FILES["img_preview"]["type"] == "image/pjpeg"))
&& ($_FILES["img_preview"]["size"] < 80000))
{
if ($_FILES["img_preview"]["error"] > 0)
{
echo "Return Code: " . $_FILES["img_preview"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["img_preview"]["name"] . "<br />";
echo "Type: " . $_FILES["img_preview"]["type"] . "<br />";
echo "Size: " . ($_FILES["img_preview"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["img_preview"]["tmp_name"] . "<br />";
//check the file into its room
if (file_exists("upload/" . $_FILES["img_preview"]["name"]))
  {
  echo $_FILES["img_preview"]["name"] . " already exists. ";
  }
else
  {
  move_uploaded_file($_FILES["img_preview"]["tmp_name"],
  "upload/" . $_FILES["img_preview"]["name"]);
  echo "Stored in: " . "upload/" . $_FILES["img_preview"]["name"];
  }
  }
  }
 else
 {
 echo "Invalid file";
 }
 ?>  

This is the upload code for the img_preview file. I would create another one for the pdf_doc file, but this one is not working right at the moment.

So, how do I increase the filesize limit to 8MB? And, for the pdf upload I would like to restrict the file type to pdf, jpg, or gif. So, I tried this as the parameters:

if ((($_FILES["img_preview"]["type"] == "image/gif")
|| ($_FILES["img_preview"]["type"] == "image/jpeg")
|| ($_FILES["img_preview"]["type"] == "image/pjpeg"))
|| ($_FILES["img_preview"]["type"] == "application/pdf"))
&& ($_FILES["img_preview"]["size"] < 80000))

but again errors. What’s the fix? Is there a more fluid way to do this?

  • 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-23T07:24:43+00:00Added an answer on May 23, 2026 at 7:24 am

    File type problem

    Since the MIME type reported by the browser (which is what you get in $_FILES) can be spoofed, you can’t rely on it. This leaves you with two reasonable options:

    1. Filter by file extension
    2. Filter using finfo_file

    Unfortunately finfo_file is not included by default on PHP < 5.3, so this leaves you with the extension check (which has worked just fine for me in the past), or using the discontinued PECL package finfo.

    Max upload size problem

    There are many PHP settings that influence this, and you need to tweak all of them to have big uploads work. Fortunately, for some time now the PHP docs have a page where everything related to file upload that can cause problems is discussed.

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

Sidebar

Related Questions

I have set the form decorators in this way: <?php $this->setElementDecorators(array( 'Label', array(array('labelTd' =>
I have a ListView control on my form set up like this in details
I have a Photo model and I want to set up a form so
In my form I have a set of input boxes where a user can
I have set the AutoSize property of the form to True and I have
I have set up a datepicker in a form using the following js: $(#Expiry).datepicker({
I want to save form position. I have successfully set Form.Location property in ApplicationSettings->PropertyBinding
I have a signup form where I'm validating user input. Here's my controller: <?php
I have a form set up like this in HTML: <input type=text name=data[type1][0] value=
This is the structure index.php app/processor.php app/.htaccess in the index.php I have this form

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.