There may be several issues:
- A file read permision issue: the file exists, but PHP (and the mkvextract it runs) don't have the permission to open it. In the rest of my answer I assume this is not happening, because you haven't added any error message containg the word permission or access to your question.
- A shell argument escaping issue: correcly passing a command argument containing whitespace and/or shell metacharacters (e.g.
"
, \
, $
). I address this with escapeshellarg below.
- A filename encoding issue: correctly specifying non-ASCII characters in filenames. I address this with mb_convert_encoding below.
For testing purposes, make a copy of the input file to /home/movies/t.mkv
, and then try echo shell_exec("mkvextract tracks /home/movies/t.mkv")
.
If that works, then rename the copy to /home/movies/t t.mkv
, and then try echo shell_exec("mkvextract tracks " . escapeshellarg("/home/movies/t t.mkv"))
. Without the escapeshellarg call, it wouldn't work, because the filename contains a space.
If that works, then the problem is with non-ASCII characters in the filename. To investigate it further, examine the output of var_dump(scandir("/home/movies/R-12"))
, and see how the letters with accents appear there. Pass it the same way to shell_exec. Don't forget about escapeshellarg.
If that works, use encoding conversion (with mb_convert_encoding) for the remaining filenames. You may want to ask a separate question about that, specifying the output of var_dump(scandir("/home/movies/R-12"))
and var_dump("X-1 ÇĞŞZ.mkv")
in your question.