dsf4s5787 2016-10-20 06:35
浏览 130
已采纳

php - 函数require-once无法找到文件

I am implementing a code where visitors can email our company.

in my gmail.php, it has this code for line 11

require_once('PHPMailerAutoload.php') or exit();

the error it gives is when i run it is

Warning: require_once(1) [function.require-once]: failed to open stream: No such file or directory in /home/maxsell/public_html/php/gmail.php on line 11

Fatal error: require_once() [function.require]: Failed opening required '1' (include_path='/home/maxsell/php:.:/usr/lib/php:/usr/local/lib/php') in /home/maxsell/public_html/php/gmail.php on line 11

and if i click on [function.require-once] it loads

The requested URL /php/function.require-once was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

I made this in our other website and it worked there. I tried changing file path in require_once but it doesn't work. gmail.php and PHPMailerAutoload.php is in the same folder.

edit: here is a directory contents directory contents

  • 写回答

2条回答 默认 最新

  • doujubeng2942 2016-10-20 06:49
    关注

    The problem is the or exit()-part.

    when i use

    require_once("test.php") or exit();
    

    i get the same error, but

    require_once("test.php");
    

    works if the file exists, or throws a correct error if it doesn't.

    also, the common syntax is

    require_once "test.php";
    

    and the or exit() part is superfluous anyway, since require quits the script itself if the file is not found.

    edit:

    after some testing i suspect that the internal workings of this curious error is that require_once is not a function but a command structure, meaning that

    require_once('PHPMailerAutoload.php') or exit();
    

    is functionally the same as

    require_once ('PHPMailerAutoload.php' or exit());
    

    since the or-operator takes precedence.

    which makes your require fail because ('PHPMailerAutoload.php' or exit()) resolves to true, effectively making php try to require(true) which must fail.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)