Good afternoon everyone !!
I'm trying to implement a program where I have to get .txt files from a folder, open them and grab the contents of this file to store in the database, I'm having trouble opening the file and viewing the contents using variables in PHP.
<?php
$extensions = array('txt'); // image extensions
$result = array();
$directory = new DirectoryIterator('C:\Users\Fernando\Desktop\Imagens produto\APPLE'); // directory to scan
$dir = "C:/Users/Fernando/Desktop/Imagens produto/APPLE";
foreach ($directory as $fileinfo) {
if ($fileinfo->isFile()) {
$extension = strtolower(pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION));
if (in_array($extension, $extensions, $dir)) {
$result[] = $fileinfo->getFilename();
$conteudo =$dir."/".$fileinfo; //fiz uma gambiarra para juntar o diretorio com o nome do arquivo, para poder abrir em uma variavel com o caminho inteiro do arquivo
//echo $conteudo."<br>";
}
}
}
$a = open($conteudo);
echo $a."<br>";
/*while (!feof ($a)){
$x = fgets($a, 5120);
echo $x."<br>";
}
fclose($a);*/
//print_r($extensions);
?>