【问题标题】:failed to open stream in php无法在 php 中打开流
【发布时间】:2012-07-25 14:38:47
【问题描述】:

我在一个简单的include 方法上收到此错误:

Warning:  include(/home/content/70/8352870/html/sites/mysite.com/preview/wp-content/themes/site-theme/mail/class.phpmailer.php)
[<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /home/content/70/8352870/html/sites/mysite.com/preview/wp-content/themes/site-theme/mail/send-message.php on line 5

我已经使用这个包含了文件:

<?php
    $path = getcwd();
    include $path.'/class.phpmailer.php';
?>

我在不使用getcwd 方法的情况下得到了同样的错误,但是这个:

include 'class.phpmailer.php';

Warning:  include(class.phpmailer.php)
[<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /home/content/70/8352870/html/sites/mysite.com/preview/wp-content/themes/site-theme/mail/send-message.php on line 10

Obiouvsly 我检查了文件位于此处:

mysite.com/preview/wp-content/themes/site-theme/mail/
class.phpmailer.php
class.pop3.php
class.smtp.php
send-message.php

我做错了什么?

【问题讨论】:

  • class.phpmailer.php 肯定在/home/content/70/8352870/html/sites/mysite.com/preview/wp-content/themes/site-theme/mail 中?
  • 你能显示print_r(glob(getcwd().'/*.php'));
  • 对了,我再检查一下,我在用尾声,有时会出花招

标签: php path include


【解决方案1】:

这与您尝试获得的行为相同,但更受信任:

(我认为 class.phpmailer 与包含它的脚本在同一路径上)

<?php
$path = dirname( __FILE__ );
include $path.'/class.phpmailer.php';
?>

【讨论】:

  • 仅供参考,自 5.3 __DIR__ === dirname( __FILE__ ) 起。并且两者都不等同于getcwd(),因为当前工作目录不一定是当前脚本的位置。
猜你喜欢
  • 2019-12-03
  • 2012-05-14
  • 2020-07-27
  • 2012-08-04
  • 1970-01-01
  • 2018-02-27
  • 2018-01-13
  • 2018-11-21
相关资源
最近更新 更多