在Windows和CentOS上PHP的include / require的不同行为(Different behavior of PHP’s include/require on Windows and CentOS)
这些是我的PHP应用程序
myApp.php
和mypartsA/main.php
。myApp.php
<?php echo ("##### myApp is starting now !!! </br>"); require_once('/parts/mypartsA/main.php'); ?>
mypartsA / main.php
<?php echo ("#### mypartsA is required </br>"); ?>
myApp.php
和mypartsA/main.php
的结构如下。Document_root | +--- test | | | +--- myApp.php | +--- parts | +--- mypartsA | +---main.php
我已经在Windows + Apache上使用了这个应用程序一年没有问题但最近我将其迁移到CentOS + Apache然后我得到与
include_path
相关的致命错误PHP Warning: require_once(/parts/mypartsA/main.php) [<a href='function.require-once'>function.require-once</a>] : failed to open stream : No such file or directory in /var/www/html/test/myApp.php on line 12 PHP Fatal error: require_once() [<a href='function.require'>function.require</a>] : Failed opening required (/parts/mypartsA/main.php’ (include_path='.:/php/includes:/usr/share/pear:/usr/share/pear/PEAR:/var/www/html') in /var/www/html/test/myAPP.php on line 12
根据PHP.net,如果定义了路径,则include_path将被忽略。 http://www.php.net/manual/en/function.include.php
我认为在我的情况下,PHP尝试从
C:\
或/
而不是从include_path
查找parts
目录。require_once(/parts/mypartsA/main.php);
因此,无论是在Windows上还是在CentOS上,
myAPP.php
结果myAPP.php
必须是致命的错误。但我的应用程序已经工作了一年,在Windows上没有错误。 PHP可以正确找到
parts
目录。可以在Windows上尝试上面的代码,看看..
##### myApp is starting now !!! #### mypartsA is required
或者得到错误?
现在,我想知道为什么在Windows上运行和在CentOS上运行相同代码的结果是不同的。
我必须检查PHP.ini中的什么指令?
我知道如果我更改此代码以使用
$ _SERVER['DOCUMENT_ROOT']
添加绝对路径。require_once($_SERVER['DOCUMENT_ROOT']./parts/mypartsA/main.php);
它会很好用。 但是有许多应用程序具有相同的编码风格,我不想改变所有这些应用程序。
这些是其他信息。
include_path值phpinfo()在Windows上显示
.;C:\PHP;C:\PHP\pear;C:\Apache2.2.22\htdocs
include_path值phpinfo()在CentOS上显示
.:/php/includes:/usr/share/pear:/usr/share/pear/PEAR:/var/www/html
These are code of my PHP applications
myApp.php
andmypartsA/main.php
.myApp.php
<?php echo ("##### myApp is starting now !!! </br>"); require_once('/parts/mypartsA/main.php'); ?>
mypartsA/main.php
<?php echo ("#### mypartsA is required </br>"); ?>
And
myApp.php
andmypartsA/main.php
are in following structure.Document_root | +--- test | | | +--- myApp.php | +--- parts | +--- mypartsA | +---main.php
I’ve used this application on Windows+Apache for a year with no problem but recently I migrate this to CentOS+Apache then I get fatal error related to
include_path
PHP Warning: require_once(/parts/mypartsA/main.php) [<a href='function.require-once'>function.require-once</a>] : failed to open stream : No such file or directory in /var/www/html/test/myApp.php on line 12 PHP Fatal error: require_once() [<a href='function.require'>function.require</a>] : Failed opening required (/parts/mypartsA/main.php’ (include_path='.:/php/includes:/usr/share/pear:/usr/share/pear/PEAR:/var/www/html') in /var/www/html/test/myAPP.php on line 12
According to PHP.net if a path is defined the include_path will be ignored. http://www.php.net/manual/en/function.include.php
I think in my case PHP tries to find
parts
directory fromC:\
or/
not frominclude_path
.require_once(/parts/mypartsA/main.php);
Therefore result of
myAPP.php
must be fatal error whether on Windows or on CentOS.But my application has been working for a year with no error on Windows. PHP can find
parts
directory correctly.Can sameone try those codes above on Windows and see..
##### myApp is starting now !!! #### mypartsA is required
or get error?
Now,I want to know is why results of same code are different between running on Windows and running on CentOS.
What dirctive in PHP.ini do I have to check ?
I know if I change this code to add absolute path with
$ _SERVER['DOCUMENT_ROOT']
.require_once($_SERVER['DOCUMENT_ROOT']./parts/mypartsA/main.php);
It’ll work well. But there are many applications with same style of coding and I don’t want to change all of them.
These are additional information.
include_path values phpinfo() shows on Windows
.;C:\PHP;C:\PHP\pear;C:\Apache2.2.22\htdocs
include_path values phpinfo() shows on CentOS
.:/php/includes:/usr/share/pear:/usr/share/pear/PEAR:/var/www/html
原文:https://stackoverflow.com/questions/15539793
最满意答案
如果您的表单数据是通过
name
属性如user[profile_attributes][gender]
(均具有user
前缀)的字段提交的,则可以检查:user
存在于params
。... if params.include?(:user)
如果由于某种原因(例如来自路由),
params[:user]
即使对于GET
请求也将具有值,那么您可以查找具有值的特定表单字段。 例如,您可以添加一个隐藏字段<%= f.hidden_field :some_field, :value => true %>
并检查你的情况
... if params[:user].include?(:some_field)
您可以选择是否通过
POST
方法检查请求... if request.post?
这也适用于其他方法,如
request.put?
用于更新方法。If your form data is submitted through fields with
name
attributes likeuser[profile_attributes][gender]
(all having theuser
prefix), you can check if the:user
exists inparams
.... if params.include?(:user)
If for some reason (like coming from the route)
params[:user]
is already going to have a value even forGET
requests, you can look for a specific form field having a value. For example, you could add a hidden field<%= f.hidden_field :some_field, :value => true %>
and check for it in your condition
... if params[:user].include?(:some_field)
You can alternatively check if the request is via the
POST
method... if request.post?
This works for other methods as well, like
request.put?
for an update method.
相关问答
更多-
就在这儿: var test = localStorage.input === 'true'? true: false; $('input').prop('checked', test); 就是为什么所有复选框都被检查。 你有一个存储在localStorage.input的全局变量。 当您调用$('input').prop('checked', test) ,将选择所有输入并应用该属性。 将状态存储在localStorage似乎是一种明智的做法,但您需要单独为每个复选框存储状态,并且需要将这些属性 ...
-
这是错误的: def create @Event = Event.new(params[:Event]) .... end 它应该是: def create @Event = Event.new(params[:event]) .... end HF ... //并且你也应该在cvariable Names中使用小写字母。 大写只能用于常量,比如ClassName! This is wrong: def create @Event = Event.new(para ...
-
在轨道上的红宝石简单的搜索(Simple search in ruby on rails)[2022-02-02]
它看起来像路由可能会搞砸了? 你确定search行动实际上被称为? 它看起来会用id search show 。 尝试添加debugger调用或Rails.logger.debug调用以查看正在调用的操作。 或者只是看看整个日志条目。 It looks like the routing might be messed up? Are you sure the search action is actually being called? It looks like it's going to show wi ... -
如果您的表单数据是通过name属性如user[profile_attributes][gender] (均具有user前缀)的字段提交的,则可以检查:user存在于params 。 ... if params.include?(:user) 如果由于某种原因(例如来自路由), params[:user]即使对于GET请求也将具有值,那么您可以查找具有值的特定表单字段。 例如,您可以添加一个隐藏字段 <%= f.hidden_field :some_field, :value => true %> 并检查 ...
-
你看过TinyMCE吗? 它配置非常简单,您只需传递相应的参数即可包含您需要的选项。 它甚至不需要任何宝石或js库。 详细信息 - http://www.tinymce.com/ Have you looked at TinyMCE ? It's pretty easy to configure and you can just pass corresponding parameters to include those options that you require. It does not not e ...
-
红宝石在轨道上form_for(ruby on rails form_for)[2023-10-01]
我没有使用calendar_date_select插件,但是您应该已经获取参数。 params[:date_range][:start] params[:date_range][:end] I haven't used the calendar_date_select plugin, but you should be getting the parameters back already. params[:date_range][:start] params[:date_range][:end] -
把这样的东西添加到你的application_controller.rb : before_action :store_ref private def store_ref cookies[:ref] = params[:ref] if params[:ref].present? end 像这样的东西给你的用户创建操作: def create @user = User.new(user_params) @user.ref = cookies[:ref] if @user.save ...
-
你提到的两个框架都可以处理满足这些要求的网站。 您还应该将Django和Symfony添加到您可能选择的列表中,因为它们也可以满足您的需求。 你有使用Ruby / PHP / Python构建应用程序的经验吗? Both of the frameworks you mention could handle a web site with those requirements. You should also add Django and Symfony to your list of possible ch ...
-
instantrails应该是你正在寻找的。 http://rubyforge.org/frs/?group_id=904 instantrails should be what you're looking for. http://rubyforge.org/frs/?group_id=904
-
尝试在轨道上的红宝石中使用表单中的下拉菜单(Attempting to utilize a drop down menu in a form in ruby on rails)[2023-08-20]
看起来你需要改变你选择使用options_for_select标签: <%= f.select :category_id, options_for_select(Category.all.collect {|c| [ c.name, c.id ] }), :include_blank => true %> 如果你想预先填充category_id <%= f.select :category_id, options_for_select(Category.all.collect {|c| [ c.name, ...