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