Vijay
Vijay

Reputation: 5433

how to read files with spaces and special characters in their name?

i have lots of videos in my server and i use the following code to get the duration of the video and it works fine..

        ob_start();
        passthru("ffmpeg -i ".$srcfile." 2>&1");
        $duration = ob_get_contents();
        ob_end_clean();

But i could not get the duration for the files which has a space or any special characters like ( ' # % etc...

I cant rename the files as it is stored already and the names of those files are also stored in db and it would take a toll to change all in a live site..

So is there any method for accessing/reading the files with special characters?

Upvotes: 1

Views: 1733

Answers (2)

Sjoerd
Sjoerd

Reputation: 75619

Quote the filename between single quotes:

    passthru("ffmpeg -i '".$srcfile."' 2>&1");

Upvotes: 0

troelskn
troelskn

Reputation: 117517

escapeshellarg

Incidentally, you should always use this for any shell arguments, less you want to make your application open to shell injection-attacks, which could be very dangerous.

Upvotes: 3

Related Questions