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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:24:58+00:00 2026-05-21T05:24:58+00:00

My code- $filename = basename($_FILES[‘file’][‘name’]); $ext = substr($filename, strrpos($filename, ‘.’) + 1); if (($ext==txt)

  • 0

My code-

$filename = basename($_FILES['file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext=="txt")
&& ($_FILES["file"]["size"] < 2000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Error: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {$newname = 'news/'.$filename;
     move_uploaded_file($_FILES['file']['tmp_name'],$newname);
     $fileread = $newname;
    //reading a file
$file = fopen($fileread, "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
  {
      //inserting each data into table
      $insert = "insert into $name (serial,data,used) values('','fgets($file)','0')";
      $query = mysqli_query($connect,$insert);
      if($query)
      {
          echo "cool";
      }
  }

So user uploads text file which contains data per line. I want to insert the data into the database till the query is executed.

What is getting inserted into db is fgets(Resource id #6) – and this keeps on going till i stop.,..it is uncontrolled…

  • 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-21T05:24:59+00:00Added an answer on May 21, 2026 at 5:24 am
      $insert = "insert into $name (serial,data,used) values('','fgets($file)','0')";
    

    You’re inserting the literal text fgets($file) into your database, because it’s embedded in the parent string. You’d want something like this, instead, which also (incidentally) removes sql injection vulnerabilities:

     $string = fgets($file);
     $string = mysql_real_escape_string($string);
     $insert = "insert into ... values ( ..., '$string', ...)";
    

    Why escape it? I don’t know what’s in that text file, but if ANY of the text contains so much as a single quote, it’ll cause that particular insert to fail with an SQL syntax error, and now you’ve got a missing line in the database.

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

Sidebar

Related Questions

I have the following $name = basename($_FILES['the_file']['name']); $size = $_FILES['the_file']['size']; $contents = $_FILES['the_file']['tmp_name']; if($size
I write the code below to delete a file: FileInfo file = new FileInfo(filename);
I'm using json to open the user popup. I used to use basename( $_FILES['userfile']['name']
The code block below works but I would like to un-comment filename = os.path.basename(filename)
So I have a program which runs. This is part of the code: FileName
here my simple code to add filename and their associated icon to virtualtreeview PFileInfoRec
I have the below code: public void OpenFile(string FileName) { if (FileName == null)
I have the following code, which will retrieve a filename from a table and
I'm currently using the following code (C#): private static void PlayLoop(string filename) { Audio
I have a unicode filename that I would like to open. The following code:

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.