1

I'm running a command to add id3 metadata to mp3 files via PHP's exec function, like so:

exec('id3v2 [options, filename etc go here] 2>&1', $output, $result);

The command is currently having no effect on the target files (ie. their id3 tags are not being updated). However, it returns 0 as the $result, outputs no errors, and if I run the exact same command from the command line it works as expected.

If anyone could suggest what I'm doing wrong, I'd be very grateful!

2
  • What $output contains after the command execution? Commented Mar 13, 2012 at 13:47
  • Ah! When I checked earlier it seemed to be empty, but now it says: fopen: ../../assets/mp3/p163tjjijs1oe61eq81q3q16rt7to5.mp3: id3v2: Permission denied Commented Mar 13, 2012 at 13:50

3 Answers 3

1

Check the $output.

This is probably a path or access right issue. For example if you run this script with the web-server priviliges it probably doesn't have the right to alter the files.

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks. I think you're right. Now I look at it, it's saying: fopen [filename]: id3v2: Permission denied ...do you have any idea what I need to do to allow it permission? I'm using other command line tools (eg. lame, sox) via PHP, and they're working fine. Do I need to somehow grant id3v2 more privileges or something?
You need to give php read nad write permissions on the file. If security is no issue just chmod 777 /path/to/dir
Ok. What would be the likely security issues? (This directory is outside the web root, and only contains mp3 files)
Maybe this was a collection of blackmail clips you wanted to add this to and others used the same computer. 777 would let other users open your file and learn all the secrets
nope. you have to give read&write permission for the file (and not the directory). something like chmod 777 or chown apache.apache. perlfect.com/articles/chmod.shtml
|
1

Does the user PHP is running under have permissions to write to those files and execute "id3v2"?

3 Comments

I'm not actually sure. Do you know how I check this? (Sorry, I'm a bit new to shell commands) I've been using other tools (lame, sox) via PHP's exec command (on the same website/server, hence presumably same user), and they have been working with no problem.
@Nick F - If other applications work and using the command line directly works, then the next logical cause is your PHP script. Perhaps your not formatting the exec command right. Can you add a side by side of the command running in the terminal and the PHP snippet with the Exec. It maybe be something as simple as the file path not being quoted. Also, I'm not sure what "2>&1" is trying to do, I haven't used Linux in a while but I thought & (ampersand) spawned a background job.
Thanks, actually this is now fixed. It turned out it was to do with the user that PHP uses. "chown" on the relevant directory/files fixed the problem (see above).
0

Try http://www.php.net/manual/en/language.operators.execution.php

Or, if id3v2 returns something you can do http://php.net/manual/en/function.shell-exec.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.