Reputation: 717
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..
Upvotes: 0
Views: 123
Reputation: 30565
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.
Upvotes: 0
Reputation: 3561
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.
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][1] call.
Upvotes: 2