Php reads the file content and saves it to the database-PHP source code

Source: Internet
Author: User
Php reads the file content and saves it to the database. php reads the file content and saves it to the database.

Script ec (2); script

The function of this program is to read the txt file in the directory and save it to the data. That's simple, next let's take a look at how I saved the txt file content to the mysql DATA table.

Include ('../boke/inc/re_conn.php ');

CheckDir ('file /');

Function CheckDir ($ dir_path) // traverses the Directory
{
If (is_dir ($ dir_path ))
{
If ($ dir_file = opendir ($ dir_path ))
{
While ($ dir_list = readdir ($ dir_file ))! = False)
{
If ($ dir_list! = "." & $ Dir_list! = "..")
{
$ Title = substr ($ dir_list, 6, strlen ($ dir_list)-4 );
// Echo $ title;
OpenFile ($ dir_path. $ dir_list, $ title );
}

}
}
Else
{
Echo ($ dir_path ."
");
}
}
Else
{
Echo ($ dir_path ."
");
}
}

Function savaDate ($ title, $ content) // save data
{
$ Title = str_replace('.txt ', '', $ title );
Echo $ title;
$ Content = addslashes ($ content );
$ SQL = "insert into fil (title, content, siteindex, filesendid, cmdype, z_type) values ('$ title',' $ content', 1, 'admin', 2, 31) ";
If (mysql_query ($ SQL ))
{
Echo 'success
';
}
Else
{
Echo mysql_error ();
}
}

Function openFile ($ filePath, $ title) // read the File Content Abstract
{

If (is_file ($ filePath ))
{
$ Content = file_get_contents ($ filePath );
If (! Empty ($ content ))
{
SavaDate ($ title, $ content );
}
Else
{
;
}
}
}
?>

Site original reprinted Note: http://www.111cn.net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.