2015-03-25 46 views
0

我想文件directory root值保存到database获取文件根值。如何从HTML表单或php

ex: 我有目录c:\xampp\htdocs\myproject\app\views\index.php的文件,但我只想得到myproject\app\views\index.php。 我想从输入类型文件中获取值,可以吗?

这就是我想要构建的过程,但这个值并不是我想要的。

not like what i want

我想,当用户在<input type='file' />点击选择文件,我想默认目录“的myproject”开放。这不是关于上传文件,我只是想从目录根值进行验证。在某些情况下,我有两个同名文件“index.php”,但其中一个文件位于myproject\view\dir1\index.php,另一个位于myproject\view\dir2\index.php。 以便将它分开是根目录。

感谢您的帮助。

回答

2

可以使用follwing:

\Yii::$app->basePath将使得像D:\xampp\htdocs\advanced\backend

\Yii::$app->request->BaseUrl将使得像localhost\advanced\backend\web\

您可以使用\Yii::$app->basePath存储图像,并使用表现出来\Yii::$app->request->BaseUrl

希望它有帮助

+0

投票@ chinmay的答案(Y) – ramadani 2015-03-25 06:08:11

+0

@chinmay我希望用户选择文件,并从 “MyProject的” 不是C秀根目录文件:\ XAMPP \ htdocs中\ myproject,而这可能吗? 当点击“中的文件时,我需要在”myproject“中打开默认目录,这不是关于上传文件,我只是想根据目录根值进行验证。文件名为“index.php”,但其中一个文件位于myproject \ view \ dir1 \ index.php,另一个位于myproject \ view \ dir2 \ index.php。 – randawahyup 2015-03-25 06:18:16

+0

对不起,我不明白。更新你的问题相应 – Chinmay 2015-03-25 06:23:50

0

请google以下。此外,在计算器搜索

$_SERVER['DOCUMENT_ROOT'] dirname(__FILE__); 
+0

我想从或某种类型的dir根,因此用户可以选择文件。 – randawahyup 2015-03-25 06:28:18