问题
In my project, I am using EasyPHP and the directory I wanted to access is
-> www/myP/profile_icon:
I am trying to access profile_icon folder by using the code:
$dir = "myP/profile_icon";
$handle = opendir($dir."/");
However, I am getting a warning:
Warning: opendir(myP/profile_icon/,myP/profile_icon/): The system cannot find the path specified. (code: 3) in C:\Program Files\EasyPHP-12.1\www\myP\functions.php
回答1:
You could try to use the full path to the file:
$dir = "C:/Program Files/EasyPHP-12.1/www/myP/profile_icon";
回答2:
Your code is in
C:\Program Files\EasyPHP-12.1\www\myP\functions.php
$dir = __DIR__. "/profile_icon";
$handle = opendir($dir."/");
This keeps working and does not rely on any system specific folders. It just relies on the internal project structure.
Note that this requires PHP 5.3. For lower versions, use
$dir = dirname(__FILE__). "/profile_icon";
回答3:
I think this is what you were looking for:
$base_dir = 'C:\Program Files\EasyPHP-12.1\www\myP';
$icon_dir = '\profile_icon';
$handle = opendir($base_dir.$icon_dir.'\');
As you're using PHP on Windows machine you mustn't pay attention to the use of the slashes. Linux let's us only use forward-slash /, however on Windows, both forward-slash / and back-slash \ are used as path separator character.
来源:https://stackoverflow.com/questions/12130166/path-to-folder-from-localhost