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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:50:03+00:00 2026-06-01T21:50:03+00:00

hopefully someone can help me here. been up all night browsing and nothing I

  • 0

hopefully someone can help me here. been up all night browsing and nothing I try seems to work, but im new to php so im slow. I need to upload 6 images, and this works great. but then I realized you can upload not only images but all other file types. Im trying to be able to limit it to just images under 100kb each. heeeeelllllllpppppp!!!! please!

function findexts ($filename) { $filename = strtolower('$filename') ; 
$exts = preg_split("[/\\.]", $filename) ;
 $n = count($exts)-1; 
 $exts = $exts[$n];
  return $exts;
   }

$ext = findexts ($_FILES['images']['name']) ; 
$ran = rand ();
$ran2 = $ran.".";

while(list($key,$value) = each($_FILES['images']['name']))
        {
            if(!empty($value))
            {
                $filename = $ran.$value;
                    $filename=str_replace(" "," _ ",$filename);// Add _ inplace of blank space in file name, you can remove this line

                    $add = "media/".$ran."$filename";
                $insert_query = "INSERT INTO ....VALUES ...";
                       //echo $_FILES['images']['type'][$key];
                 // echo "<br>";
                    copy($_FILES['images']['tmp_name'][$key], $add);
                    chmod("$add",0777);

        mysql_query($insert_query);

            }

        }
  • 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-01T21:50:05+00:00Added an answer on June 1, 2026 at 9:50 pm

    See the answer to both your questions here:

    https://stackoverflow.com/a/9153419/723855

    Add this function to your script (modified from link):

    function acceptFileUpload($thefile){
        if(isset($_FILES[$thefile])) {
            $errors     = array();
            $maxsize    = 2097152;
            $acceptable = array(
                'application/pdf',
                'image/jpeg',
                'image/jpg',
                'image/gif',
                'image/png'
            );
    
            if(($_FILES[$thefile]['size'] >= $maxsize) || ($_FILES[$thefile]["size"] == 0)) {
                $errors[] = 'File too large. File must be less than 2 megabytes.';
            }
    
            if(!in_array($_FILES[$thefile]['type'], $acceptable)) && (!empty($_FILES[$thefile]["type"]))) {
                $errors[] = 'Invalid file type. Only PDF, JPG, GIF and PNG types are accepted.';
            }
    
            if(count($errors) !== 0) {
                return true;
            } else {
                foreach($errors as $error) {
                    echo '<script>alert("'.$error.'");</script>';
                    return false;
                }
    
                die(); //Ensure no more processing is done
            }
        }
    }
    

    Then in your script change your while loop to use this function to check for a valid file:

    while(list($key,$value) = each($_FILES['images']['name']))
        {
            if(!empty($value))
            {
                if(acceptFileUpload('images'))
                {
                $filename = $ran.$value;
                    $filename=str_replace(" "," _ ",$filename);// Add _ inplace of blank space in file name, you can remove this line
    
                    $add = "media/".$ran."$filename";
                $insert_query = "INSERT INTO ....VALUES ...";
                       //echo $_FILES['images']['type'][$key];
                 // echo "<br>";
                    copy($_FILES['images']['tmp_name'][$key], $add);
                    chmod("$add",0777);
    
        mysql_query($insert_query);
                }
            }
    
        }
    

    I might not have that parameter right that is getting passed to acceptFileUpload().

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

Sidebar

Related Questions

I'm new here and I'm very stuck. I need help. Hopefully someone can tell
everyone, i have no idea why this doesn't work hopefully someone here can help
Hopefully someone can help here, it's incredibly frustrating! I have a couple of iOS
Quick question hopefully someone can help out here. I'm trying to copy and paste
Hopefully someone here can help me! I'm trying to set up fancybox so when
This is a weird one, but hopefully someone can give me an idea here.
Hopefully someone can help here. I have a ListView that is populated by a
Hopefully someone here can help me out - basically I have a logging class
Hopefully someone can help me out here. I'm using Visual Studio 2005 and creating
Hopefully, someone here can give me some light. I have been researching this issue

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.