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..
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.
The web environment.
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
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.
Related
I am using php-fpm 7.4.3 on ubuntu 20.04. My blacklist of opcache doesn't work at all. Scripts I visited are cached when file_cache is enabled. Here's my configures.
php.ini
opcache.save_comments=0
opcache.blacklist_filename="/etc/php/opcache_blacklist.txt"
opcache.file_cache="/tmp/php"
opcache.file_cache_fallback=0
opcache_blacklist.txt
/*
/**
/**.php
/*.php
*.php
**
**.php
test.php
<pre>
<?php
print_r(opcache_get_status(true));
?>
</pre>
Some information from test.php
[used_memory] => 9821016
[num_cached_scripts] => 44
[num_cached_keys] => 45
[max_cached_keys] => 16229
[blacklist_misses] => 2
[scripts] => Array
(
....
)
There is a strange thing: everytime I refresh the test.php, blacklist_misses is increased by 1.
If I disable file_cache (opcache.file_cache=) in php.ini, num_cached_scripts and num_cached_keys become 0, blacklist_misses keeps increasing, blacklist_miss_ratio is always 100.
PHP documentation doesn't tell me that file_cache will affect blacklist, is this by design or a bug?
You are getting the expected bahavior. Basically you told php to execlude everything from caching!.
A normal blacklist file would look like:
/var/www/html/notcachedfile.php
/var/www/html/notcachedfolder/*
So file notcachedfile.php and everything in notcachedfolder will not be cached.
A cache miss means PHP tries to retrieve data from the opcache, but that specific data is not currently in the opcache
So the reason why blacklist_misses is increased everytime you refresh your test.php file is because it's matched by the pattern you provided in your opcache_blacklist.txt
/*
Which means everything that is part of the / (The root directory) including your test.php file will not be in the cache, hence it shows a cache miss everytime.
I’m encountering a problem with file upload in PHP. I’m using Dropzone.js which calls a PHP script.
The PHP environment runs on Docker, and the PHP version is : 7.2.28
When I upload an image with Firefox 72 on Mac OSX, I get this in $_FILES :
Array\n(\n [file] => Array\n (\n [name] => image.png\n [type] => \n [tmp_name] => \n [error] => 3\n [size] => 0\n )\n\n)\n,
According to the documentation: error 3 means UPLOAD_ERR_PARTIAL.
The problem happens only with Firefox on Mac OSX, with PNG images with this specific size (158ko).
Other file size (even tiny or big files), other browsers, other file types, or other operating systems work fine.
The docker image runs on 3 different servers, and the problem happens on each installation.
I tried some solutions that I read on the internet, but none of them worked:
php_sapi_name() returns apache2handler
I tried to add 'Accept-Ranges: none' to my php file.
Do you have a clue on what might happen?
Thanks in advance,
First question ever here...
I have OwnCloud running on a Raspberry Pi 2.
I can access it locally with no issues.
Ports 22, 80, and 443 have been forwarded.
I can SSH into the machine from outside local.
But, if I try to access http/https from outside of my local network, I get:
"You are accessing the server from an untrusted domain.
Please contact your administrator. If you are an administrator of this instance, configure the "trusted_domain" setting in config/config.php. An example configuration is provided in config/config.sample.php.
Depending on your configuration, as an administrator you might also be able to use the button below to trust this domain."
I have the following in my config.php:
'trusted_domains' =>
array (
0 => '192.168.10.10'
),
Commenting it out fixes the problem, but that's not the best solution.
I've spent some time looking around forums looking for answers and feel I have everything set up correctly. I'm just missing something...
FYI the router is an ASUS RT-N66W
When you're accessing it remotely, you're not using 192.168.10.10, you'd be using a public IP address or external hostname. It's this which you need to add to your trusted domains. Let's say you're accessing it using an external IP of 12.34.56.78:
'trusted_domains' =>
array (
0 => '192.168.10.10',
1 => '12.34.56.78'
),
And if you also decide to use an external hostname:
'trusted_domains' =>
array (
0 => '192.168.10.10',
1 => '12.34.56.78',
2 => 'owncloud.mydomain.com'
),
You can add as many of those as is necessary for your setup.
Additional to Nicks remarks there is also the example config file (config.sample.php) that helps you understand how to manipulate the real config file (config.php).
In case somebody wonders where to find the configuration files:
you will find them here
/var/www/owncloud/config/config.php
/var/www/owncloud/config/config.sample.php
Ok, I have two Linux boxes running behind a proxy server. Both boxes are set to bypass the filtering by connecting on port 801.
Box A - Fedora Core 12 / PHP 5.3.1
Box B - RHEL 6 / PHP 5.3.3
On Box A I am able to use file_get_contents() to conenct to an external site.
<?php
$opts = array(
'http' => array(
'proxy' => 'tcp://10.136.132.1:801',
'request_fulluri' => true
)
);
$cxContext = stream_context_set_default($opts);
echo file_get_contents("http://www.google.com");
This results in Google's homepage being displayed.
On Box B I run the same code, but get this error:
Warning: file_get_contents(http://www.google.com): failed to open stream: Permission denied
Both boxes are on the same network and behind the same proxy server. Is there a setting I am missing in Apache or PHP that will allow file_get_contents to work on Box B?
It sounds like you have SELinux enabled, it blocks any outgoing connections by Apache by default. Try running this in your shell as root:
setsebool -P httpd_can_network_connect on
More info on SELinux booleans can be found here:
http://wiki.centos.org/TipsAndTricks/SelinuxBooleans
That could be because google blocks requests that seem to come from Bot or Script.
Maybe because Box A sets additional headers when requesting to google.
Try to open other website on Box b
I am a PHP developer who has started learning Ruby on Rails. I love how easy it is to get up and running developing Rails applications. One of the things I love most is WEBrick. It makes it so you don't have to configure Apache and Virtual Hosts for every little project you are working on. WEBrick allows you to easily start up and shut down a server so you can click around your web application.
I don't always have the luxury of working on a Ruby on Rails app, so I was wondering how I might configure (or modify) WEBrick to be able to use it to serve up my PHP projects and Zend Framework applications.
Have you attempted this? What would be the necessary steps in order to achieve this?
To get php support in webrick you can use a handler for php files. To do this you have to extend HttpServlet::AbstractServlet and implement the do_GET and do_POST methods. These methods are called for GET and POST requests from a browser. There you just have to feed the incoming request to php-cgi.
To get the PHPHandler to handle php files you have to add it to the HandlerTable of a specific mount. You can do it like this:
s = HTTPServer.new(
:Port => port,
:DocumentRoot => dir,
:PHPPath => phppath
)
s.mount("/", HTTPServlet::FileHandler, dir,
{:FancyIndexing => true, :HandlerTable => {"php" => HTTPServlet::PHPHandler}})
The first statement initializes the server. The second adds options to the DocumentRoot mount. Here it enables directory listings and handling php files with PHPHandler. After that the server can be started with s.start().
I have written a PHPHandler myself as I haven't found one somewhere else. It is based on webricks CGIHandler, but reworked to get it working with php-cgi. You can have a look at the PHPHandler on GitHub:
https://github.com/questmaster/WEBrickPHPHandler
You can use nginx or lighttpd
Here's a minimal lighttpd config.
Install PHP with FastCGI support and adjust the "bin-path" option below for your system. You can install it with MacPorts using sudo port install php5 +fastcgi
Name this file lighttpd.conf
then simply run lighttpd -f lighttpd.conf from any directory you'd like to serve.
Open your webbrowser to localhost:8000
lighttpd.conf:
server.bind = "0.0.0.0"
server.port = 8000
server.document-root = CWD
server.errorlog = CWD + "/lighttpd.error.log"
accesslog.filename = CWD + "/lighttpd.access.log"
index-file.names = ( "index.php", "index.html",
"index.htm", "default.htm" )
server.modules = ("mod_fastcgi", "mod_accesslog")
fastcgi.server = ( ".php" => ((
"bin-path" => "/opt/local/bin/php-cgi",
"socket" => CWD + "/php5.socket",
)))
mimetype.assign = (
".css" => "text/css",
".gif" => "image/gif",
".htm" => "text/html",
".html" => "text/html",
".jpeg" => "image/jpeg",
".jpg" => "image/jpeg",
".js" => "text/javascript",
".png" => "image/png",
".swf" => "application/x-shockwave-flash",
".txt" => "text/plain"
)
# Making sure file uploads above 64k always work when using IE or Safari
# For more information, see http://trac.lighttpd.net/trac/ticket/360
$HTTP["useragent"] =~ "^(.*MSIE.*)|(.*AppleWebKit.*)$" {
server.max-keep-alive-requests = 0
}
If you'd like to use a custom php.ini file, change bin-path to this:
"bin-path" => "/opt/local/bin/php-fcgi -c" + CWD + "/php.ini",
If you'd like to configure nginx to do the same, here's a pointer.
I found this, but I really think it isn't worth the hassle. Is making a virtual host (which isn't even necessary) that difficult? In the time it would take you to set this up to work with PHP, if you can even get it working, you could have written a script that creates virtual host entries for you, making it as easy as webrick.
It looks like WEBrick has CGI support, which implies that you can get PHP running by invoking it as a CGI script. The #! line at the top of each executable file would just need to point towards the absolute path to php-cgi.exe.
It's worth noting that you'd need to remove the #! line when moving the file to any other server that doesn't think of PHP as a CGI script, which would be ... uh ... all of'em.