读取文件和重定向时,php文件不存在

my code to read local file then search word then return line then add some words before line .

my file is

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:55
#EXTINF:9.999022,
test55.ts
#EXTINF:9.999033,
test56.ts
#EXTINF:9.099122,
test57.ts
#EXTINF:9.999033,
test58.ts
#EXTINF:9.999033,
test59.ts
#EXTINF:9.999033,
test60.ts

i use this code to do what i want

$server_name = $_SERVER['SERVER_NAME'];
$file = "/var/www/files/test.m3u8";
$character = '.ts';
$tslines = file($file);
foreach ($tslines as $tslines_num => $tsline) {
//echo $line_num; echo $line;
$charPos = strpos($tsline, $character);
if ($charPos !== false) {
$newtsline1 = $tsline;
$newtsline2 = "http://$server_name/$newtsline1";
echo $newtsline2;
} else {
echo $tsline;
}
}

result from my code is correct

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:11
#EXT-X-MEDIA-SEQUENCE:356
#EXTINF:9.999044,
http://localhost/test356.ts
#EXTINF:9.999111,
http://localhost/test357.ts
#EXTINF:9.998967,
http://localhost/test358.ts
#EXTINF:9.999044,
http://localhost/test359.ts
#EXTINF:10.099033,
http://localhost/test360.ts
#EXTINF:9.999033,
http://localhost/test361.ts

the problem when i start use my code for watch video i get error from apache File does not exist: /var/www/html/test356.ts

my web path is: /var/www/html ts and m3u8 files path is: /var/www/files

how to make apache use this path to read ts files ?

try to change,

$file = "/var/www/files/test.m3u8";

to

$file = dirname(__FILE__)."files/test.m3u8";