Failed to open directory windows

Странные ошибки при запуске приложения в Visual Studio 2019 (Xamarin C#)

Ошибка при запуске приложения для Android в Visual Studio&Xamarin
Invalid argument: cannot open transport registration socketpair List of devices attached * daemon.

Ошибки в Visual Studio 2019
Здравствуйте, проблема такая. Имеется код на СИ. Когда пытаюсь его запускать в программе, выдает.

Visual studio xamarin тест андроид-приложения без гипервизора Windows
Добрый день! Столкнулся с проблемой того, что в BIOS нет параметра отвечающего за технологию.

При запуске скомпилированного проекта Visual Studio 2010 возникает ошибка: В ходе построения произошли ошибки
Последние 7 листингов из книги не работают. Не могут они все быть с ошибками. Скорее всего что-то.

Ты смог решить эту проблему?

Добавлено через 27 секунд
ITLDS, ты смог решить эту проблему?

Заказываю контрольные, курсовые, дипломные и любые другие студенческие работы здесь или здесь.

В коде возникли ошибки при переходе с Visual studio 2013 на Visual studio 2017
Добрый день, решил попробовать поменять свою 2013 студию на 2017 и заметил такую проблему, при.

Ошибка D8027 при компилировании в Visual Studio 2019
Всем привет! Я новичок в С++ и у меня возникла проблема с компилированием программ в Visual.

При открытии любого проекта Visual Studio 2019 зависает
Привет При открытии любого проекта Visual Studio 2019 зависает. Грузит процессор на 50% и ни в.

Зависание Visual Studio 2017/2019 при любом изменении в XAML
Студия зависает секунд на 40 при любой правке в XAML. Проект большой, очень много в нём XAML.

scandir fail to open directory

I am having trouble with scandir() . I am trying to display the files in my snaps -directory on a page under the subdomain in my cloud.

This is the PHP I used.

and this is the error.

I have no idea what else to do.

3 Answers 3

You probably assume, that the current work directory is next to the script scandir() is written in, which (in many cases) isn’t.

Given that error, your snaps directory would have to have the absolute path of

Make sure that this is the correct location for the directory, and that the webserver has the rights to access it.

First off you’re trying to display a few files that will not render as images. ex. (.zip).

Also are you making sure you’re not trying to display the first two index values » . » and » .. «? I’m thinking this part of your code might not be the issue.

Not the answer you’re looking for? Browse other questions tagged php or ask your own question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

PHP — Failed to open stream : No such file or directory

In PHP scripts, whether calling include() , require() , fopen() , or their derivatives such as include_once , require_once , or even, move_uploaded_file() , one often runs into an error or warning:

Failed to open stream : No such file or directory.

What is a good process to quickly find the root cause of the problem?

7 Answers 7

There are many reasons why one might run into this error and thus a good checklist of what to check first helps considerably.

Let’s consider that we are troubleshooting the following line:

Читайте также:  Операторы печати windows права

Checklist

1. Check the file path for typos

    either check manually (by visually checking the path)

or move whatever is called by require* or include* to its own variable, echo it, copy it, and try accessing it from a terminal:

Then, in a terminal:

2. Check that the file path is correct regarding relative vs absolute path considerations

  • if it is starting by a forward slash «/» then it is not referring to the root of your website’s folder (the document root), but to the root of your server.
    • for example, your website’s directory might be /users/tony/htdocs
  • if it is not starting by a forward slash then it is either relying on the include path (see below) or the path is relative. If it is relative, then PHP will calculate relatively to the path of the current working directory.
    • thus, not relative to the path of your web site’s root, or to the file where you are typing
    • for that reason, always use absolute file paths

In order to make your script robust in case you move things around, while still generating an absolute path at runtime, you have 2 options :

    use require __DIR__ . «/relative/path/from/current/file» . The __DIR__ magic constant returns the directory of the current file.

define a SITE_ROOT constant yourself :

    at the root of your web site’s directory, create a file, e.g. config.php

in config.php , write

in every file where you want to reference the site root folder, include config.php , and then use the SITE_ROOT constant wherever you like :

These 2 practices also make your application more portable because it does not rely on ini settings like the include path.

3. Check your include path

Another way to include files, neither relatively nor purely absolutely, is to rely on the include path. This is often the case for libraries or frameworks such as the Zend framework.

Such an inclusion will look like this :

In that case, you will want to make sure that the folder where «Zend» is, is part of the include path.

You can check the include path with :

You can add a folder to it with :

4. Check that your server has access to that file

It might be that all together, the user running the server process (Apache or PHP) simply doesn’t have permission to read from or write to that file.

To check under what user the server is running you can use posix_getpwuid :

To find out the permissions on the file, type the following command in the terminal:

5. Check PHP settings

If none of the above worked, then the issue is probably that some PHP settings forbid it to access that file.

Three settings could be relevant :

  1. open_basedir
    • If this is set PHP won’t be able to access any file outside of the specified directory (not even through a symbolic link).
    • However, the default behavior is for it not to be set in which case there is no restriction
    • This can be checked by either calling phpinfo() or by using ini_get(«open_basedir»)
    • You can change the setting either by editing your php.ini file or your httpd.conf file
  2. safe mode
    • if this is turned on restrictions might apply. However, this has been removed in PHP 5.4. If you are still on a version that supports safe mode upgrade to a PHP version that is still being supported.
  3. allow_url_fopen and allow_url_include
    • this applies only to including or opening files through a network process such as http:// not when trying to include files on the local file system
    • this can be checked with ini_get(«allow_url_include») and set with ini_set(«allow_url_include», «1»)

Corner cases

If none of the above enabled to diagnose the problem, here are some special situations that could happen :

1. The inclusion of library relying on the include path

It can happen that you include a library, for example, the Zend framework, using a relative or absolute path. For example :

But then you still get the same kind of error.

This could happen because the file that you have (successfully) included, has itself an include statement for another file, and that second include statement assumes that you have added the path of that library to the include path.

For example, the Zend framework file mentioned before could have the following include :

Читайте также:  Как убрать пароль с компьютера при включении windows 10 учетной

which is neither an inclusion by relative path, nor by absolute path. It is assuming that the Zend framework directory has been added to the include path.

In such a case, the only practical solution is to add the directory to your include path.

2. SELinux

If you are running Security-Enhanced Linux, then it might be the reason for the problem, by denying access to the file from the server.

To check whether SELinux is enabled on your system, run the sestatus command in a terminal. If the command does not exist, then SELinux is not on your system. If it does exist, then it should tell you whether it is enforced or not.

To check whether SELinux policies are the reason for the problem, you can try turning it off temporarily. However be CAREFUL, since this will disable protection entirely. Do not do this on your production server.

If you no longer have the problem with SELinux turned off, then this is the root cause.

To solve it, you will have to configure SELinux accordingly.

The following context types will be necessary :

  • httpd_sys_content_t for files that you want your server to be able to read
  • httpd_sys_rw_content_t for files on which you want read and write access
  • httpd_log_t for log files
  • httpd_cache_t for the cache directory

For example, to assign the httpd_sys_content_t context type to your website root directory, run :

If your file is in a home directory, you will also need to turn on the httpd_enable_homedirs boolean :

In any case, there could be a variety of reasons why SELinux would deny access to a file, depending on your policies. So you will need to enquire into that. Here is a tutorial specifically on configuring SELinux for a web server.

3. Symfony

If you are using Symfony, and experiencing this error when uploading to a server, then it can be that the app’s cache hasn’t been reset, either because app/cache has been uploaded, or that cache hasn’t been cleared.

You can test and fix this by running the following console command:

4. Non ACSII characters inside Zip file

Apparently, this error can happen also upon calling zip->close() when some files inside the zip have non-ASCII characters in their filename, such as «é».

A potential solution is to wrap the file name in utf8_decode() before creating the target file.

Credits to Fran Cano for identifying and suggesting a solution to this issue

To add to the (really good) existing answer

Shared Hosting Software

open_basedir is one that can stump you because it can be specified in a web server configuration. While this is easily remedied if you run your own dedicated server, there are some shared hosting software packages out there (like Plesk, cPanel, etc) that will configure a configuration directive on a per-domain basis. Because the software builds the configuration file (i.e. httpd.conf ) you cannot change that file directly because the hosting software will just overwrite it when it restarts.

With Plesk, they provide a place to override the provided httpd.conf called vhost.conf . Only the server admin can write this file. The configuration for Apache looks something like this

Have your server admin consult the manual for the hosting and web server software they use.

File Permissions

It’s important to note that executing a file through your web server is very different from a command line or cron job execution. The big difference is that your web server has its own user and permissions. For security reasons that user is pretty restricted. Apache, for instance, is often apache , www-data or httpd (depending on your server). A cron job or CLI execution has whatever permissions that the user running it has (i.e. running a PHP script as root will execute with permissions of root).

A lot of times people will solve a permissions problem by doing the following (Linux example)

This is not a smart idea, because the file or directory is now world writable. If you own the server and are the only user then this isn’t such a big deal, but if you’re on a shared hosting environment you’ve just given everyone on your server access.

What you need to do is determine the user(s) that need access and give only those them access. Once you know which users need access you’ll want to make sure that

Читайте также:  Драйвера для hp deskjet d2460 для windows 10

That user owns the file and possibly the parent directory (especially the parent directory if you want to write files). In most shared hosting environments this won’t be an issue, because your user should own all the files underneath your root. A Linux example is shown below

The user, and only that user, has access. In Linux, a good practice would be chmod 600 (only owner can read and write) or chmod 644 (owner can write but everyone can read)

Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory

I have a project on Laravel 5 and I work with it at the office and at home too. It works fine, but recently at home it stopped working. Laravel show me two ErrorException

I’m searching problem decision with Google and find information about correct rights. All advice is about Linux, but I’am work in Windows at the office and at home too.

When I try to clear application cache and view cache, artisan talk to me — . cleared. But cache data and views are present in storage.

How can I fix this problem?

Thanks in advance!

22 Answers 22

The best way to solve this problem is, go to directory laravel/bootstrap/cache and delete config.php file. or you can rename it as well like config.php.old And your problem will be fix. Happy coding 🙂

You should typically run the php artisan config:cache command as part of your production deployment routine. As a solution to your problem, I suggest you recreate the cache file, for faster configuration loading.

To do this, run the following Artisan commands on your command line

  • php artisan cache:clear
  • php artisan config:cache

You can programmatically execute the command by adding the following to your routes:

And then call the clear-cache route from your browser.

I hope this is helpful.

After some research I understand — I have very similar, but different root project locations and its cached in /bootstrap/cache . After cache clearing project started.

Actually I faced this issue when I moved my project from server to local.

four basic folders are required cache, sessions, testing, views

In My case sessions was missing might be in gitignore.

So I manually created session folder and refreshed browser and it was working.

So any of the missing folder if we delete this problem can be solved.

This type of issue generally occurs while migrating one server to another, one folder to another. Laravel keeps the cache and configuration (file name ) when the folder is different then this problem occurs.

Solution Run Following command:

Apache + WSL on windows

This is a silly mistake, and a different answer compared to the others, but I’ll add it because it happened to me.

If you use WSL (linux bash on windows) to manage your laravel application, while using your windows apache to run your server, then running any caching commands in the wsl will store the linux path rather than the windows path to the sessions and other folders.

Solution

Simply run the cache clearing commands in the powershell, rather than in WSL.

Was enough for me.

I solved this problem via creating storage\framework\sessions folder.

Try with these commands that have been useful with those errors

In case of shared hosting when you do not have command line access simply navigate to laravel/bootstrap/cache folder and delete (or rename) config.php and you are all done!

The best way to solve this problem is, go to directory laravel/bootstrap/cache and delete all files from cache.

To do this, run the following Artisan commands on your command line
1. php artisan config:clear
2. php artisan cache:clear
3. php artisan config:cache

In your panel or server, you can execute commands by adding the following to your routes:

And then call the www.yourdomain.com/clear-cache route from your browser.

changing name of /bootstrap/cache/config.php to config.php.old doesn’t work for me neither clearing cache with the commands artisan

  1. php artisan config:clear
  2. php artisan cache:clear
  3. php artisan config:cache

And for some weird reason I can’t change permission for the owner on the directories, so my solution was running my IDE (Visual Studio Code) as admin, and everything works.

My project is in an F:/ path of another disk.

Maybe there is an issue with your composer file. You could try:

Оцените статью