0

I'm using the PECL extension to extract the ID3 tags from an mp3 and this is my code to print_r the array :

<?php
$tag = id3_get_tag( "/var/www/music/rem.mp3");
print_r ($tag);
?>

but when i run the file in the browser nothing happens i tried to execute it in the terminal and it works perfectly fine it gives me the output:

maniteja@maniteja:~$ sudo php /var/www/index.php
Array
(
    [title] => Lexter - Who's Laughing now (Mr. Day Lens remix)
    [album] => LEXTER - Who's Laughing now
    [releaseTime] => 2013
    [track] => 01
    [genre] => (255)
    [artist] => Алексей
    [publisher] => Jamendo
    [copyright] => 2013-11-28T21:32:03+01:00 Алексей. Licensed to the public underhttp://creativecommons.org/licenses/by/3.0/ verify at http://www.jamendo.com/album/129077/
    [encodedBy] => Jamendo : http://www.jamendo.com | LAME
    [commInfo] => http://www.jamendo.com
    [copyrightInfo] => http://creativecommons.org/licenses/by/3.0/
    [webOffAudioFile] => http://www.jamendo.com/en/track/1083749
    [webOffArtist] => http://www.jamendo.com/en/artist/Mr._Day_Lens
    [webOffAudioSrc] => http://www.jamendo.com/en/album/129077
    [webOffPubl] => http://www.jamendo.com
    [taggingTime] => 2013-11-28T20:33:57
)

is syntax wrong??? I'm new at this..

maniteja
  • 687
  • 2
  • 16
  • 32
  • Have you had a look in your error logs? – ajtrichards Jan 14 '14 at 14:20
  • sorry i'm really new at this i don't know how to check with the error logs :/ – maniteja Jan 14 '14 at 14:21
  • Why are you executing it with `sudo` on the command line? – hanzi Jan 14 '14 at 14:22
  • Try looking in `/var/log/`. If there's no PHP error file in there have a look at `nano /etc/php.ini` and see where the error log is located. This is if your on Linux... – ajtrichards Jan 14 '14 at 14:22
  • You can also add `error_reporting(E_ALL); ini_set("display_errors", true);` at the top of your PHP file to view errors in the browser – Jon Jan 14 '14 at 14:23
  • Also, try creating a file containing `` and execute that both in your browser and on the command line. It's possible that both use different php.ini files (PHP's configuration) and the web one does not load the id3 extension. – hanzi Jan 14 '14 at 14:24
  • @ajtrichards `phpinfo();` will also show the path to the real `php.ini` file. – Peon Jan 14 '14 at 14:24
  • i have check the error log and this is what i found on the files end `[Tue Jan 14 19:54:33.176239 2014] [:error] [pid 1006] [client 127.0.0.1:42232] PHP Warning: id3_get_tag(/var/www/music/rem.mp3): failed to open stream: Permission denied in /var/www/index.php on line 2` – maniteja Jan 14 '14 at 14:25
  • 3
    You don't have permission to read the files in `/var/www/music`. You'll need to allow access to your web server – ajtrichards Jan 14 '14 at 14:28
  • downvoted - you should be able to get further than "nothing happens" on your own - e.g. at least confirming that the script is executing. – symcbean Jan 14 '14 at 14:32
  • @ajtrichards how can i allow access to the web server? – maniteja Jan 14 '14 at 14:38
  • changed the folder permissions and worked perfectly fine :D thank you sir @ajtrichards – maniteja Jan 14 '14 at 14:46

2 Answers2

2

Edit:

As @ajtrichards says:
"You don't have permission to read the files in /var/www/music. You'll need to allow access to your web server"

Go to your /var/www/music folder and give the right permissions for your server to READ in there.

If you use Apache:
How to make a directory apache readable on ubuntu


PHP has two environments.

  1. The web environment.
  2. The CLI environment.

Your extension works perfectly on the CLI environment because you added the PECL extension on the CLI php.ini.

You need to make sure the extension is added to the web php.ini.

To test it, make a test.php with a phpinfo call.

And access it via browser.
This will output all the php.ini configuration for the "web" PHP.
Then search for your ID3 extension in all the list of extensions.
If it does not display, then is not added to the "web environment" php.ini.

To add it, you must do the same that you did to add it to the CLI php.ini

Something like, adding this line

extension=id3.so

PS:
Dude, where's my php.ini?

More info on ID3 http://www.php.net/manual/en/id3.installation.php

Community
  • 1
  • 1
Tomás
  • 3,501
  • 3
  • 21
  • 38
0

This works via the command line PHP as the user root has permission to read from the folder /var/www/music, as Maniteja uses sudo php to run the php file.

However, when the script is running via PHP in the web browser the web server does not have the permission to read from the folder, hence the error:

PHP Warning: id3_get_tag(/var/www/music/rem.mp3): failed to open stream: Permission denied in /var/www/index.php on line 2

To resolve the problem - grant read access to your web server user.

ajtrichards
  • 29,723
  • 13
  • 94
  • 101
  • You don't know if the user `maniteja` has read access. But notice that we are sure `root` user can read it as he executes `sudo php ...` – Tomás Jan 14 '14 at 21:51