dsfykqq3403 2019-07-31 08:32
浏览 352

警告:require_once(./ mailer / class.phpmailer.php):无法打开流:

Tree:

--myproject
----mailer
-------class.phpmailer.php
----test
-------index.php
----site.php
----class.php
----db.php
----index.php

index.php: (both)

<?php 
require_once '../site.php';
?>

site.php:

<?php
require_once "class.php";
?>

class.php

<?php
require_once 'db.php';
require_once('./mailer/class.phpmailer.php');
?>

When I visit test it shows:

Warning: require_once(./mailer/class.phpmailer.php): failed to open stream: No such file or directory in C:\wamp\www\myproject\class.php on line 3


Fatal error: require_once(): Failed opening required './mailer/class.phpmailer.php' (include_path='.;C:\php\pear') in C:\wamp\www\myproject\class.php on line 3


I also tried include_once but same error!

  • 写回答

3条回答 默认 最新

  • dsoxcj7276 2019-07-31 08:40
    关注

    You're calling the

    require_once('./mailer/class.phpmailer.php');
    

    From inside index.php, so the file is two levels above.

    Change

    require_once('./mailer/class.phpmailer.php');
    

    to

    require_once('../mailer/class.phpmailer.php');
    

    UPDATE

    Just realized you need both index.php files working. It's not the prettiest solution, but you can do it like this:

    /test/index.php

    <?php
    
    $nested = true;
    require_once '../site.php';
    
    ?>
    

    /index.php

    <?php 
    
    $nested = false;
    require_once 'site.php';
    
    ?>
    

    This new "nested" variable will determine if the file is inside a directory or on the base.

    Edit your class.php to look like this:

    <?php
    
    require_once 'db.php';
    
    if ($nested == true)
    require_once('../mailer/class.phpmailer.php');
    
    elseif ($nested == false)
    require_once('./mailer/class.phpmailer.php');
    
    ?>
    

    This should fix the problem in both files.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)