this is a simple question but i watched the php doc and i didn't found anything so i'm asking you if you got any idea / way to reach my goal.
I'm reading a file and trying to get it to start writing at a specifique word.
(The file i get is coming from an Curl command:
curl -F 'file@logbackup-infitarif' https://mylink
My php:
<?php
// print_r($_FILES);
print_r($_FILES["file"]);
$file = fopen($_FILES["file"]["tmp_name"], 'r');
print_r($file);
var_dump(get_resource_type($file));
print(stream_get_line($file, $lengh, $ending = "speedup"));
?>
Actually with this code, it's reading all the file from the start -> "speedup". But i want it to start at the word "to the word / sentence "total size is" .
The text in the file it's reading:
logbackup-final.txt
logbackup-final.txt 0000777 0002002 0000144 00000000331 14303633743 013533 0 ustar stag users 2022-08-30
receiving incremental file list
2022/08/30 16:09:56|test/
2022/08/30 16:09:56|test/DiskStation214_20220622.dss
sent 47 bytes received 11,370 bytes 7,611.33 bytes/sec
total size is 15,402 speedup is 1.35
Any idea or way to do that's? Thanks if so! :)
CodePudding user response:
That is to complex, just do a simple read of the file, line by line and check each line for the info you are searching for
$find_str = 'total size is';
$fp = @fopen($_FILES["file"]["tmp_name"], "r");
if ($fp) {
while (($line = fgets($fp, 4096)) !== false) {
if ( strpos($line, $find_str) !== false ) {
$keep_for_later = $line;
}
}
fclose($fp);
}
echo $keep_for_later;