1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> |
---|
2 | <HTML> |
---|
3 | <HEAD> |
---|
4 | <META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.17"> |
---|
5 | <TITLE>phpgwapi - VFS Class: Basic Functions</TITLE> |
---|
6 | <LINK HREF="vfs-4.html" REL=next> |
---|
7 | <LINK HREF="vfs-2.html" REL=previous> |
---|
8 | <LINK HREF="vfs.html#toc3" REL=contents> |
---|
9 | </HEAD> |
---|
10 | <BODY> |
---|
11 | <A HREF="vfs-4.html">Next</A> |
---|
12 | <A HREF="vfs-2.html">Previous</A> |
---|
13 | <A HREF="vfs.html#toc3">Contents</A> |
---|
14 | <HR> |
---|
15 | <H2><A NAME="sec:basic_functions"></A> <A NAME="s3">3.</A> <A HREF="vfs.html#toc3">Basic Functions</A></H2> |
---|
16 | |
---|
17 | <P>These are two functions you'll need to know before we get into |
---|
18 | relativity.</P> |
---|
19 | <H2><A NAME="sec:path_parts"></A> <A NAME="ss3.1">3.1</A> <A HREF="vfs.html#toc3.1">path_parts ()</A> |
---|
20 | </H2> |
---|
21 | |
---|
22 | <P>The job of path_parts () is to translate any given file location |
---|
23 | into its many component parts for any relativity. The values passed |
---|
24 | to path_parts () are:</P> |
---|
25 | <P> |
---|
26 | <PRE> |
---|
27 | string |
---|
28 | relatives |
---|
29 | object |
---|
30 | </PRE> |
---|
31 | </P> |
---|
32 | <P>'string' is the path you want to translate, 'relatives' is the |
---|
33 | standard relativity array, and 'object' specifies how you would like |
---|
34 | the return value: if 'object' is True, an object will be returned; |
---|
35 | if 'object' is False, an array will be returned. I think you'll find |
---|
36 | the object easier to deal with, and we'll be using it throughout |
---|
37 | this document. The most important returned values (but not all) for |
---|
38 | path_parts () are:</P> |
---|
39 | <P> |
---|
40 | <PRE> |
---|
41 | fake_full_path |
---|
42 | fake_leading_dirs |
---|
43 | fake_extra_path |
---|
44 | fake_name |
---|
45 | real_full_path |
---|
46 | real_leading_dirs |
---|
47 | real_extra_path |
---|
48 | real_name |
---|
49 | </PRE> |
---|
50 | </P> |
---|
51 | <P>Just like you would think, fake_full_path contains the full virtual |
---|
52 | path of 'string', and real_full_path contains the full real path |
---|
53 | of 'string'. The fake_name and real_name variables should always |
---|
54 | be the same, and contain the final file or directory name. The leading_dirs |
---|
55 | contain everything except the name, and the extra_path is everything |
---|
56 | from the / before "home" to the end of the leading_dirs. To better |
---|
57 | illustrate, here is an example:</P> |
---|
58 | <P> |
---|
59 | <PRE> |
---|
60 | $p = $GLOBALS['phpgw']->vfs->path_parts (array( |
---|
61 | 'string' => '/home/jason/dir/file', |
---|
62 | 'relatives' => array( |
---|
63 | RELATIVE_NONE |
---|
64 | ) |
---|
65 | )); |
---|
66 | </PRE> |
---|
67 | </P> |
---|
68 | <P> |
---|
69 | <UL> |
---|
70 | <LI>$p->fake_full_path - /home/jason/dir/file</LI> |
---|
71 | <LI>$p->fake_leading_dirs - /home/jason/dir</LI> |
---|
72 | <LI>$p->fake_extra_path - home/jason/dir</LI> |
---|
73 | <LI>$p->fake_name - file</LI> |
---|
74 | <LI>$p->real_full_path - /var/www/egroupware/files/home/jason/dir/file</LI> |
---|
75 | <LI>$p->real_leading_dirs - /var/www/egroupware/files/home/jason/dir |
---|
76 | </LI> |
---|
77 | <LI>$p->real_extra_path - home/jason/dir</LI> |
---|
78 | <LI>$p->real_name - file</LI> |
---|
79 | </UL> |
---|
80 | </P> |
---|
81 | <P>As you can see, path_parts () is a very useful function and will |
---|
82 | save you from doing those darn substr ()'s yourself. For those of |
---|
83 | you used to the prior VFS, note that <EM>getabsolutepath () is depreciated</EM>. |
---|
84 | getabsolutepath () still exists (albeit in a much different form), |
---|
85 | and is responsible for some of the path translation, but it is an |
---|
86 | <EM>internal</EM> function only. Applications should only use path_parts (). |
---|
87 | We have shown you how to use path_parts () so you can experiment |
---|
88 | with it using different paths and relativities as we explore relativity.</P> |
---|
89 | <H2><A NAME="sec:cd"></A> <A NAME="ss3.2">3.2</A> <A HREF="vfs.html#toc3.2">cd ()</A> |
---|
90 | </H2> |
---|
91 | |
---|
92 | <P>Part of the overall goal for the VFS in eGroupWare is to give |
---|
93 | the user a seamless experience during their session. For example, |
---|
94 | if they upload a file using a file manager to the directory /home/my_group/project1, |
---|
95 | and then go to download an email attachment, the default directory |
---|
96 | will be /home/my_group/project1. This is accomplished using the cd |
---|
97 | () function. Examples: </P> |
---|
98 | <P> |
---|
99 | <PRE> |
---|
100 | /* cd to their home directory */ |
---|
101 | $GLOBALS['phpgw']->vfs->cd (array( |
---|
102 | 'string' => '/' |
---|
103 | )); |
---|
104 | |
---|
105 | /* cd to /home/jason/dir */ |
---|
106 | $GLOBALS['phpgw']->vfs->cd (array( |
---|
107 | 'string' => '/home/jason/dir', |
---|
108 | 'relative' => False, |
---|
109 | 'relatives' => array( |
---|
110 | RELATIVE_NONE |
---|
111 | ) |
---|
112 | )); |
---|
113 | |
---|
114 | /* When following the above, cd's to /home/jason/dir/dir2 */ |
---|
115 | $GLOBALS['phpgw']->vfs->cd (array( |
---|
116 | 'string' => 'dir2', |
---|
117 | 'relative' => True |
---|
118 | )); |
---|
119 | </PRE> |
---|
120 | </P> |
---|
121 | <P>If 'relative' is True, the 'string' is simply appended to the |
---|
122 | current path. If you want to know what the current path is, use $GLOBALS['phpgw']->vfs->pwd |
---|
123 | ().</P> |
---|
124 | <P>Now you're ready for relativity.</P> |
---|
125 | <HR> |
---|
126 | <A HREF="vfs-4.html">Next</A> |
---|
127 | <A HREF="vfs-2.html">Previous</A> |
---|
128 | <A HREF="vfs.html#toc3">Contents</A> |
---|
129 | </BODY> |
---|
130 | </HTML> |
---|