I'm trying to implement a PHP script that converts a .stravactivity file to GPX - it's using github code, what's the best way to handle a file and pass in to variable $filename
Getting this error when I try to open through cli:
I'm trying to implement a PHP script that converts a .stravactivity file to GPX - it's using github code, what's the best way to handle a file and pass in to variable $filename
Getting this error when I try to open through cli:
The issue is caused by this part of the code:
$pwd = $_SERVER['PWD'];
$filePath = realpath($pwd . DIRECTORY_SEPARATOR . $filename);
if (false === ($fh = fopen($filePath, 'r'))) {
die('Couldnt open ' . $filename);
}
Which I guess serves the author's purposes but is quite odd: it builds a path out of the directory in which the script lives and whatever gets passed in $argv[1]. As you already pass a full path to the file in $argv[1] that doesn't work. Very quick fix might be
//$pwd = $_SERVER['PWD'];
$filePath = $argv[1];
if (false === ($fh = fopen($filePath, 'r'))) {
die('Couldnt open ' . $filename);
}
that is, using the value passed in $argv[1] "as is". Obviously this also would allow you to simplify the code above but I'll leave that as an exercise for you.