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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:36:59+00:00 2026-05-13T12:36:59+00:00

i have one question when we give option to web user to import data

  • 0

i have one question

when we give option to web user to import data into mysql table, is this secure?

for example

    <form method="post" action="import.php" enctype="multipart/form-data">

    <input id="file1" name="file1" type="file">

 <input type="submit" name="button" id="button" value="Submit" >
    </form> 

and in import.php we have following code

        <?php
       $theFile = $_FILES['file1'];
         $tmp_name1 = $theFile['tmp_name'];
        $row = 1;
        if (($handle = fopen($tmp_name1, "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
         $num = count($data);

        // SQL insert statement
        }
        fclose($handle);
        }

my question is, if some one upload any script or .exe or virus this will go to web server temp directory how we can secure it?

what will be safe way ?

Thanks

  • 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-13T12:37:00+00:00Added an answer on May 13, 2026 at 12:37 pm

    That is not secure. At the very least you need to verify that the file was indeed an uploaded file and not a file already on the server like /etc/passwd. To do that you need to use is_uploaded_file().

    Example:

    <?php
    if (is_uploaded_file($_FILES['file1']['tmp_name'])) {
        $tmp_name1 = $_FILES['file1']['tmp_name'];
        if (($handle = fopen($tmp_name1, "r")) !== FALSE) {
            while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                $num = count($data);
    
                // SQL insert statement
            }
        fclose($handle);
        }
    }
    

    ?>

    You also should rename any file uploaded to your server as leaving the name of the file unchanged could lead to remote file attack where someone executes the file on your server.

    Finally, if the file upload is only supposed to accept certain file type, like images, then you should definitely check to make sure the file is actually an image. At the very least check the file extension to make sure it is a .png, .gif, .jpg, etc. If it is a .exe then reject it immediately as it is obviously is not an image and thus of no use to you.

    <?php
        if (is_uploaded_file($_FILES['file1']['tmp_name'])) {
    
            $allowedExtensions = array("txt","csv","htm","html","xml","css","doc","xls","rtf","ppt","pdf","swf","flv","avi","wmv","mov","jpg","jpeg","gif","png"); 
            if (!in_array(end(explode(".", strtolower($_FILES['file1']['name']))), $allowedExtensions)) { 
                // Bad file type. Error!  
            }
            else {
                $tmp_name1 = $_FILES['file1']['tmp_name'];
                if (($handle = fopen($tmp_name1, "r")) !== FALSE) {
                    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                        $num = count($data);
    
                        // SQL insert statement
                    }
                    fclose($handle);
                }
            }
        }
    ?>    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's the question. Give only one reason you think why have OODB failed or
Background This question is in two parts. I have a one-way WCF operation hosted
I have a simple question related to one-line programming. First an example: function test(a)
I have a similar question to this one SQL products/productsales I want to do
I have two String.printable mysteries in the one question. First, in Python 2.6: >>>
I have a question similar to the one here: Event handlers inside a Javascript
I have a question about best practices regarding how one should approach storing complex
I have a model Question with a field called userid , before one ask
Similar questions to this one have been asked but none seem to address my
I have a query that pulls up questions from one table and answers from

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.