N
N
Name2018-04-06 14:02:11
PHP
Name, 2018-04-06 14:02:11

Add contents of txt files from folder to database?

There is a folder in it about 2 thousand txt files.
help me write a script how to add the contents of txt files to the database
in text - the contents of the files
in the title - the title of the file
put paragraphs in the tags < p > < / p >
maybe there is an example script ready

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Vorobyov, 2018-04-06
@User782

$dir_array=array();
$dir = opendir('Path to your folder with txt files');
while ($file = readdir ($dir)) {
if($file=="."||$file=="..") continue;
$dir_array[]=$file; }
closedir($dir);
sort($dir_array);
$total = count($dir_array);
for($i=0;$i<$total;$i++){
$txt=file_get_contents('folder path'.$dir_array[$i]);
print_r($dir_array[$i]);
$query=mysql_query("INSERT INTO `your table` (`title`,`text`) values ​​('$dir_array[$i]','$txt')");
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question