require(vendor/autoload.php):无法打开流 [英] require(vendor/autoload.php): failed to open stream

查看:1615
本文介绍了require(vendor/autoload.php):无法打开流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经发布了很多次,但是对我来说似乎是一个不同的问题.

I know that this issue has been posted many times, but for me it seems to be a different problem.

确实是这个错误

警告:require(vendor/autoload.php):无法打开流:第3行的C:\ xampp \ htdocs \ site_web \ send_mail.php中没有此类文件或目录

Warning: require(vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\site_web\send_mail.php on line 3

致命错误:require():无法在第3行的C:\ xampp \ htdocs \ site_web \ send_mail.php中打开所需的'vendor/autoload.php'(include_path ='C:\ xampp \ php \ PEAR')

Fatal error: require(): Failed opening required 'vendor/autoload.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\site_web\send_mail.php on line 3

出现在我的代码从这一行开始的地方:

appears at the begining of my code from this line:

require 'vendor/autoload.php';

因此,我想我的计算机中一定有一个/vendor/autoload.php文件(我已经安装了作曲器并运行composer require phpmailer/phpmailer).

So, I guess there must be a /vendor/autoload.php file somewhere in my computer (I have installed composer and ran composer require phpmailer/phpmailer).

因此,我在Windows命令行中使用dir /s autoload.php查找了此文件,并在此处找到了一个文件:C:\Windows\SysWOW64\vendor\autoload.php

So, I looked for this file using: dir /s autoload.php in the Windows command line, and found one here: C:\Windows\SysWOW64\vendor\autoload.php,

但是对我来说, syswow64 文件夹与 autoload.php 无关,我看不到这里缺少的内容.

but for me, syswow64 folder has nothing to see with autoload.php, I don't see what I am missing here.

推荐答案

正在运行的composer install缺少的内容,它将导入您的软件包并创建供应商文件夹以及自动加载脚本.

What you're missing is running composer install, which will import your packages and create the vendor folder, along with the autoload script.

确保您的相对路径正确.例如,PHPMailer中的示例脚本位于项目根目录下的examples/中,因此从此处加载composer自动加载器的正确相对路径将为../vendor/autoload.php.

Make sure your relative path is correct. For example the example scripts in PHPMailer are in examples/, below the project root, so the correct relative path to load the composer autoloader from there would be ../vendor/autoload.php.

C:\Windows\SysWOW64\vendor\autoload.php中找到的autoload.php可能是全局作曲家安装-通常在其中放置phpcs,phpunit,phpmd等之类的东西.

The autoload.php you found in C:\Windows\SysWOW64\vendor\autoload.php is probably a global composer installation – where you'll usually put things like phpcs, phpunit, phpmd etc.

composer update 不是是同一件事,可能不是您要使用的东西.如果您的代码已使用当前的软件包版本进行了测试,则运行update可能会导致损坏,可能需要进一步的工作和测试,因此,除非您有特定的原因并确切了解其含义,否则请不要运行update.为了进一步说明-您可能应该只在本地运行composer update,而不要在服务器上运行,因为它很可能会破坏生产中的应用程序.

composer update is not the same thing, and probably not what you want to use. If your code is tested with your current package versions then running update may cause breakages which may require further work and testing, so don't run update unless you have a specific reason to and understand exactly what it means. To clarify further – you should probably only ever run composer update locally, never on your server as it is reasonably likely to break apps in production.

我经常会抱怨人们不能使用作曲家,因为他们不能在服务器上运行它(例如,因为它是共享的并且没有外壳访问权限).在这种情况下,您可以仍然使用composer:在本地运行(没有这种限制的环境),然后上载它与所有其他PHP脚本一起生成的本地供应商文件夹.

I often see complaints that people can't use composer because they can't run it on their server (e.g. because it's shared and they have no shell access). In that case, you can still use composer: run it locally (an environment that has no such restrictions), and upload the local vendor folder it generates along with all your other PHP scripts.

运行composer update 会执行composer install,如果您当前没有vendor文件夹(即您有新的项目签出),则composer install有效执行composer update,但是了解两者之间的区别仍然很重要,因为它们肯定是不可可以互换的.

Running composer update also performs a composer install, and if you do not currently have a vendor folder (i.e. you have a new checkout of a project), then composer install effectively performs a composer update, but it's still vital to understand the difference between the two as they are definitely not interchangeable.

请注意,也可以通过命名单个软件包来更新它,例如:

Note that it is also possible to update a single package by naming it, for example:

composer update ramsey/uuid

这将重新解析您在composer.json中指定的版本,并将其安装在您的供应商文件夹中,并更新您的composer.lock文件以进行匹配.如果您只需要对一个软件包进行特定的更新,则与一般的composer update相比,它引起问题的可能性要小得多.

This will re-resolve the version specified in your composer.json and install it in your vendor folder, and update your composer.lock file to match. This is far less likely to cause problems than a general composer update if you just need a specific update to one package.

Composer 2.0(即将推出)应该消除安装和更新结果之间所有剩余的矛盾之处.

Composer 2.0 (out soon) should remove any remaining inconsistencies between install and update results.

这篇关于require(vendor/autoload.php):无法打开流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆