【问题标题】:Why am getting the error `failed to open stream: No such file or directory`?为什么会收到错误“无法打开流:没有这样的文件或目录”?
【发布时间】:2022-01-29 14:45:05
【问题描述】:

对于 beolw 代码,我收到警告 - require_once(C:\xampp\htdocs\abcd\application\controllers/vendor/autoload.php): failed to open stream: No such file or directory。我不知道为什么会出现这个错误,因为autoload.php 文件存在于vendor 文件夹中。并且该文件夹存在于根目录中。composer_autoloadtrueconfig\autoload.php 中。有人能告诉我这个问题的可能原因吗?非常感谢任何帮助。

控制器

<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once __DIR__ . '/vendor/autoload.php';
//require_once __DIR__ . '\vendor\autoload.php'; //also tried reversing the slashes like this

class Reports extends Layout_Controller
{

}

作曲家安装错误

【问题讨论】:

  • Composer update --ignore-platform-reqs 如果它不起作用,请尝试这个意味着删除供应商文件并执行 composer install
  • @SaiTarun 都试过了。 Composer update --ignore-platform-reqs 运行成功,但我的错误是一样的。我无法运行composer install,它显示了一些错误。请更新问题
  • @SaiTarun 你能告诉为什么供应商和自动加载之前的salshes在这一行中是相反的require_once(C:\xampp\htdocs\abcd\application\controllers/vendor/autoload.php)。我认为这是错误的地方
  • @user17189691 不,这样就可以了
  • PHP 说没有这样的文件,所以路径一定有问题...运行if(file_exists('C:/xampp/htdocs/abcd/application/controllers/vendor/autoload.php')) echo "file exists!";menu start &gt; cmd.exe 并输入cd C:/xampp/htdocs/abcd/application/controllers/vendor 然后dir,是自动加载。 php 有没有?

标签: php codeigniter routes codeigniter-3 php-7


【解决方案1】:

您似乎在 Windows 上使用基于 unix 的目录分隔符。 建议你使用php常量DIRECTORY_SEPARATOR:

...
require_once implode([__DIR__, 'composer', 'autoload_real.php'], DIRECTORY_SEPARATOR);

这是 composer 自动生成的,所以你也可以运行:

composer dump-autoload

在 Windows 中使用正确的 Windows 样式路径生成它。

【讨论】:

  • 我应该在哪里写这行?在 venodr\autoload.php 中? require_once implode([__DIR__, 'composer', 'autoload_real.php'], DIRECTORY_SEPARATOR);
  • 我试过composer dump-autoload,它没有生成require_once implode([__DIR__, 'composer', 'autoload_real.php'], DIRECTORY_SEPARATOR);,虽然它显示了成功消息generating autoload filesgenerated autoload fles
  • 在屏幕截图的第 5 行中是的,但您很可能会遇到类似的问题。可能最简单的解决方案是在 Windows 中安装 Composer 并运行 composer dump-autoload
  • 你是同样的错误还是不同的错误?
  • 我应该从中删除第 7 行吗?
【解决方案2】:

我对@9​​87654321@ 有同样的问题,编辑@Mark 的答案如下

require_once implode(DIRECTORY_SEPARATOR, [__DIR__, 'vendor/composer', 'vendor/autoload.php']);

它成功了!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-25
    • 2019-07-27
    • 2013-12-15
    • 2014-03-02
    • 1970-01-01
    • 2016-12-20
    • 1970-01-01
    相关资源
    最近更新 更多