试图通过将 php.ini 放在 wordpress root 中来打开 allow_url_fopen 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14652465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:43:10  来源:igfitidea点击:

trying to turn on allow_url_fopen by putting php.ini in wordpress root does not work

phpwordpresscpanel

提问by rugbert

ok so, Im building a fancy pants wordpress theme and part of the theme has php getting image widths and using those numbers to resize page elements. It works fine on my local machine, but when I put the theme on my hosted server using cpanel, it doesnt work.

好的,我正在构建一个漂亮的裤子 wordpress 主题,并且该主题的一部分具有 php 获取图像宽度并使用这些数字来调整页面元素的大小。它在我的本地机器上运行良好,但是当我使用 cpanel 将主题放在我的托管服务器上时,它不起作用。

I get this error

我收到这个错误

Warning: getimagesize() [function.getimagesize]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/yoursite/public_html/wpsite/wp-content/themes/yourtheme/styles/login.php on line 7

Warning: getimagesize(http://yoursite.com/wpsite/wp-content/uploads/2012/11/logo1.png) [function.getimagesize]: failed to open stream: no suitable wrapper could be found in /home/yoursite/public_html/wpsite/wp-content/themes/yourtheme/styles/login.php on line 7

SO I thought if I made a php.ini file in the wordpress's root directory with this in it:

所以我想如果我在 wordpress 的根目录中创建了一个 php.ini 文件,里面有这个:

[PHP]
allow_url_fopen = 1

That would work, but it wont.

那行得通,但行不通。

Is there anyway to get this to work?

有没有办法让这个工作?

回答by John Smith

Try to add this code to your .htaccess file:

尝试将此代码添加到您的 .htaccess 文件中:

php_value allow_url_fopen On

If it does not work, you will need ask your hosting provider about your php.ini file location, if it exists. If it does not, ask them to set this up for you in global php.ini file. Usually it's /etc/php.ini

如果它不起作用,您需要向您的托管服务提供商询问您的 php.ini 文件位置(如果存在)。如果没有,请让他们在全局 php.ini 文件中为您设置。通常它是/etc/php.ini

回答by Sarah Kemp

Other plugin developers seem to use cURLto get around allow_url_fopen restrictions. It is probably best for you to find a way to make your theme work without requiring allow_url_fopen to be enabled. Many providers turn this off for security reasons.

其他插件开发人员似乎使用 cURL来绕过 allow_url_fopen 限制。您最好找到一种无需启用 allow_url_fopen 即可使主题正常工作的方法。许多提供商出于安全原因将其关闭。

回答by Doug

Using cURL will bypass the issue. Some information and details that may be helpful can be found here:

使用 cURL 将绕过这个问题。可以在此处找到一些可能有用的信息和详细信息:

PHP Curl And Cookies

PHP 卷曲和饼干

回答by rugbert

None of these seemed to work on my host, and this is for a wordpress theme so it had to be a fix that could work for everyone so I just used jQuery. Tho if a users has their javascript turned off it wont work but I can live with that.

这些似乎都不适用于我的主机,这是针对 wordpress 主题的,因此它必须是一个适用于所有人的修复程序,所以我只使用了 jQuery。如果用户关闭了他们的 javascript,它就无法工作,但我可以忍受。

回答by jasdhfiu-asef-aesf-asef-a-sgaa

If you are on cPanel 11.58+ this is an option within the cPanel. You can do enable this by following these steps: 1. Login to cPanel. 2. Select "MultiPHP INI Editor" under the "Software" section 3. Select the domain you want to make this change for from the drop down 4. The first option will be "allow_url_fopen".

如果您使用的是 cPanel 11.58+,这是 cPanel 中的一个选项。您可以按照以下步骤启用此功能: 1. 登录到 cPanel。2. 在“软件”部分下选择“MultiPHP INI 编辑器” 3. 从下拉列表中选择您要对其进行更改的域 4. 第一个选项将是“allow_url_fopen”。

If you want to make the above change global in WHM you can so do something similar in multiphpini editor.

如果您想在 WHM 中进行上述更改,您可以在 multiphpini 编辑器中执行类似的操作。

However, if you are on an older cPanel version you will have to edit your php.ini manually.

但是,如果您使用的是较旧的 cPanel 版本,则必须手动编辑 php.ini。

https://documentation.cpanel.net/display/ALD/MultiPHP+INI+Editor+for+cPanel

https://documentation.cpanel.net/display/ALD/MultiPHP+INI+Editor+for+cPanel

回答by Crazy

allow_url_fopen = on

Add to php.ini or php5.ini

添加到 php.ini 或 php5.ini

Works with Joomla 3.1 hope that helps.

与 Joomla 3.1 一起使用希望有所帮助。