Hi @layito , Can you explain your problem so that we can help you better.
Do you want to save the contents of the file in a database table or upload the file and save the filename instead?
layito liked this reply
Hello, so my question was how to save the contents of a file in a database table
So you want to read the contents of the file and store them in the database table. Is that right?
layito liked this reply
Isn't it better to upload the file to the storage and store only the path of the file in the database table column?
layito liked this reply
No maybe in another situation , in my case i need the data that's the most important.
Do you need to store the data from a <file_name>.txt in a database?
// this is the data in my <file_name>.txt
accepting 1.6 0.66332 [2, 2, 2, 1, 1, 2, 1, 3, 1, 1]
accepts 1.3 0.45826 [1, 2, 1, 1, 1, 2, 2, 1, 1, 1]
accident -2.1 0.83066 [-2, -2, -1, -3, -4, -2, -2, -1, -2, -2]
accidental -0.3 0.45826 [-1, -1, 0, 0, 0, 0, 0, 0, -1, 0]
accidentally -1.4 0.91652 [-2, 0, -2, 0, -3, -1, -1, -1, -2, -2]
accidents -1.3 0.78102 [-1, -1, -1, -1, -2, 0, -3, -1, -2, -1]
accomplish 1.8 0.6 [1, 2, 3, 2, 2, 2, 1, 1, 2, 2]
if you need only first and second col you can just write code like this:
<?php
$fileName = "filename.txt";
public function make_lex_dict()
{
$lex_dict = [];
$fp = fopen($fileName, "r");
if (!$fp) {
die("Cannot load file");
}
while (($line = fgets($fp, 4096)) !== false) {
list($word, $measure) = explode("\t", trim($line));
$lex_dict[] = [$word,$measure]
}
return $lex_dict;
}
print_r(make_lex_dict());
layito liked this reply
Thanks dear, it was helpful.
i dont't know if you can help me to do the to do the inverse, export the data of a table to a file txt
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community