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

The Archive Base Latest Questions

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

I made a PHP upload file script. Now, I don’t want people uploading files

  • 0

I made a PHP upload file script. Now, I don’t want people uploading files that are huge and I don’t want them to upload PHP files either. Here’s my current PHP script:

<?php
// Where the file is going to be placed 
$target_path = "files/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
    $length = 10;
    $characters = '123456789abcdefghijklmnopqrstuvwxyz';
    $string="";
    for($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }
$pos = strrpos(basename( $_FILES['uploadedfile']['name']), ".");
$ext = str_split(basename( $_FILES['uploadedfile']['name']), $pos);
$target_path = $target_path.$string.$ext[1]; 
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "<h2>Your file has been uploaded!</h2><br /><p>Your file has been uploaded successfully. <a href='".$target_path."'>Click here</a> to see the file you uploaded.
    <br /><br /><br />
    <h2>A link to your file</h2><br />The full link to your file is:
    <br /><br />
    <code>http://www.americaspoeticsoul.com/extras/upload/".$target_path."</code></p>";
} else{
    echo "<span class='error'>There was an error uploading the file, please try again.</span>";
}
?>

How would I set a max file upload size and allow only certain file types such as only JPEGs, GIFs, PNGs, and HTML files?

Thanks in advance,
Nathan

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

    You can check the file size using $_FILES['uploadedfile']["size"]. The client-supplied file type is available in ...["type"].

    But for your code you will want to probe the $ext variable against a whitelist (just looking for extensions to forbid might not be a good idea):

    if (in_array($ext, array("jpeg","gif","png","txt","html"))) {
        if (move_uploaded_file(...
    

    At this point it might be advisable to consider a readymade helper class/script for all the upload checking. Your code is quite unreadable already.

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

Sidebar

Related Questions

I have a file upload script that works [finally] but want to have users
I have a very simple file upload PHP script. I am testing with a
I made a small script which basically uses jQuery uplodify to upload files to
I am trying to upload a file of 1GB size using php script and
I am developing a script in PHP for uploading files to a MySQL database.
I have a set of files for a custom-made CMS, and now that the
I've got an upload button I've made in Flash that links to a PHP
Below is a watermark function I made for my php photo upload script. I
For some reason, my PHP-upload field doesn't accept pdf-files. I don't get it cause
Let's say that I have a file (file1.php) with a simple form with the

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.