Question

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..

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top