When I run this code from /test
route, it works well. But when I run it from job or command it fails(fopen cannot find the file). What is the difference of these two ways to run the method?
$path = 'tempdir1/tempdir2' /* works from the `/test` route, fails from the job class */
fopen($path, 'r');
It seems the problem is path. That's why you should always use absolute paths for example:
public_path('test/tempdir/tempdir2');
because you never know from which directory your code will be run.
In Laravel there are many such helpers for example base_path()
or storage_path()