Path to folder from localhost

时光毁灭记忆、已成空白 提交于 2019-12-11 00:35:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!