1<?php
2 echo fastdfs_client_version() . "\n";
3
4 /*
5 $meta_list=array('witdh'=>1024, 'heigth'=>768, 'color'=>'red');
6 $file_info = fastdfs_storage_upload_slave_by_filebuff("/usr/include/stdio.h", 'group1', 'M00/01/14/wKgAxU5n9gUIAAAAAAAD8uiojuUAAAAEgP_8YAAAAQK66492', '_100x100', 'h', $meta_list);
7 if ($file_info)
8 {
9 	var_dump($file_info);
10	$group_name = $file_info['group_name'];
11	$remote_filename = $file_info['filename'];
12 }
13 else
14 {
15     $group_name = '';
16     $remote_filename = '';
17 }
18
19 //$result = fastdfs_storage_set_metadata1($group_name, $remote_filename,
20 //       $meta_list, FDFS_STORAGE_SET_METADATA_FLAG_OVERWRITE);
21 // echo "fastdfs_storage_set_metadata result: $result\n";
22
23 var_dump(fastdfs_storage_get_metadata($group_name, $remote_filename));
24 error_log("errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info());
25 */
26
27 /*
28 $file_id = $group_name . FDFS_FILE_ID_SEPERATOR . 'M00/00/02/wKjRbExc_qIAAAAAAABtNw6hsnM56585.part2.c';
29
30 var_dump(fastdfs_get_file_info1($file_id));
31 exit(1);
32 */
33
34 echo 'fastdfs_tracker_make_all_connections result: ' . fastdfs_tracker_make_all_connections() . "\n";
35 var_dump(fastdfs_tracker_list_groups());
36
37 $tracker = fastdfs_tracker_get_connection();
38 var_dump($tracker);
39
40 if (!fastdfs_active_test($tracker))
41 {
42	error_log("errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info());
43	exit(1);
44 }
45
46 $server = fastdfs_connect_server($tracker['ip_addr'], $tracker['port']);
47 var_dump($server);
48 var_dump(fastdfs_disconnect_server($server));
49 var_dump($server);
50
51 var_dump(fastdfs_tracker_query_storage_store_list());
52
53 $storage = fastdfs_tracker_query_storage_store();
54 if (!$storage)
55 {
56	error_log("errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info());
57	exit(1);
58 }
59
60 $server = fastdfs_connect_server($storage['ip_addr'], $storage['port']);
61 if (!$server)
62 {
63        error_log("errno1: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info());
64        exit(1);
65 }
66 if (!fastdfs_active_test($server))
67 {
68	error_log("errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info());
69	exit(1);
70 }
71
72 //var_dump(fastdfs_tracker_list_groups($tracker));
73 $storage['sock'] = $server['sock'];
74 $file_info = fastdfs_storage_upload_by_filename("/usr/include/stdio.h", null, array(), null, $tracker, $storage);
75 if (!$file_info)
76 {
77        echo "fastdfs_storage_upload_by_filename fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
78 }
79 else
80 {
81	$group_name = $file_info['group_name'];
82	$remote_filename = $file_info['filename'];
83
84	var_dump($file_info);
85	$finfo = fastdfs_get_file_info($group_name, $remote_filename);
86        if (!$finfo)
87        {
88            echo "fastdfs_get_file_info fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
89        }
90        else
91        {
92	    var_dump($finfo);
93        }
94
95	$master_filename = $remote_filename;
96	$prefix_name = '.part1';
97	$slave_file_info = fastdfs_storage_upload_slave_by_filename("/usr/include/stdio.h",
98		$group_name, $master_filename, $prefix_name);
99        if ($slave_file_info !== false)
100        {
101        var_dump($slave_file_info);
102
103        $generated_filename = fastdfs_gen_slave_filename($master_filename, $prefix_name);
104        if ($slave_file_info['filename'] != $generated_filename)
105        {
106                echo "${slave_file_info['filename']}\n != \n${generated_filename}\n";
107        }
108
109        echo "delete slave file return: " . fastdfs_storage_delete_file($slave_file_info['group_name'], $slave_file_info['filename']) . "\n";
110        }
111        else
112        {
113                echo "fastdfs_storage_upload_slave_by_filename fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
114        }
115
116	echo "delete file return: " . fastdfs_storage_delete_file($file_info['group_name'], $file_info['filename']) . "\n";
117 }
118
119 $file_id = fastdfs_storage_upload_by_filename1("/usr/include/stdio.h", null, array('width'=>1024, 'height'=>800, 'font'=>'Aris', 'Homepage' => true, 'price' => 103.75, 'status' => FDFS_STORAGE_STATUS_ACTIVE), '', $tracker, $storage);
120 fastdfs_disconnect_server($storage);
121 if (!$file_id)
122 {
123        echo "fastdfs_storage_upload_by_filename1 fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
124 }
125 else
126 {
127	$master_file_id = $file_id;
128	$prefix_name = '.part2';
129	$slave_file_id = fastdfs_storage_upload_slave_by_filename1("/usr/include/stdio.h",
130		$master_file_id, $prefix_name);
131	if ($slave_file_id !== false)
132	{
133	var_dump($slave_file_id);
134
135	$generated_file_id = fastdfs_gen_slave_filename($master_file_id, $prefix_name);
136	if ($slave_file_id != $generated_file_id)
137	{
138		echo "${slave_file_id}\n != \n${generated_file_id}\n";
139	}
140
141	echo "delete file $slave_file_id return: " . fastdfs_storage_delete_file1($slave_file_id) . "\n";
142	}
143        else
144        {
145                echo "fastdfs_storage_upload_slave_by_filename1 fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
146        }
147
148	echo "delete file $file_id return: " . fastdfs_storage_delete_file1($file_id) . "\n";
149 }
150
151 $file_info = fastdfs_storage_upload_by_filebuff("this is a test.", "txt");
152 if (!$file_info)
153 {
154        echo "fastdfs_storage_upload_by_filebuff fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
155 }
156 else
157 {
158	var_dump($file_info);
159	$group_name = $file_info['group_name'];
160	$remote_filename = $file_info['filename'];
161
162	var_dump(fastdfs_get_file_info($group_name, $remote_filename));
163
164	$ts = time();
165	$token = fastdfs_http_gen_token($remote_filename, $ts);
166	echo "token=$token\n";
167
168	$file_content = fastdfs_storage_download_file_to_buff($file_info['group_name'], $file_info['filename']);
169	echo "file content: " . $file_content . "(" . strlen($file_content) . ")\n";
170 	$local_filename = 't1.txt';
171	echo 'storage_download_file_to_file result: ' .
172		fastdfs_storage_download_file_to_file($file_info['group_name'], $file_info['filename'], $local_filename) . "\n";
173
174	echo "fastdfs_storage_set_metadata result: " . fastdfs_storage_set_metadata(
175		$file_info['group_name'], $file_info['filename'],
176		array('color'=>'', 'size'=>32, 'font'=>'MS Serif'), FDFS_STORAGE_SET_METADATA_FLAG_OVERWRITE) . "\n";
177
178	$meta_list = fastdfs_storage_get_metadata($file_info['group_name'], $file_info['filename']);
179	var_dump($meta_list);
180
181	$master_filename = $remote_filename;
182	$prefix_name = '.part1';
183	$file_ext_name = 'txt';
184	$slave_file_info = fastdfs_storage_upload_slave_by_filebuff('this is slave file.',
185		$group_name, $master_filename, $prefix_name, $file_ext_name);
186        if ($slave_file_info !== false)
187        {
188        var_dump($slave_file_info);
189
190        $generated_filename = fastdfs_gen_slave_filename($master_filename, $prefix_name, $file_ext_name);
191        if ($slave_file_info['filename'] != $generated_filename)
192        {
193                echo "${slave_file_info['filename']}\n != \n${generated_filename}\n";
194        }
195
196        echo "delete slave file return: " . fastdfs_storage_delete_file($slave_file_info['group_name'], $slave_file_info['filename']) . "\n";
197        }
198        else
199        {
200                echo "fastdfs_storage_upload_slave_by_filebuff fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
201        }
202
203	echo "delete file return: " . fastdfs_storage_delete_file($file_info['group_name'], $file_info['filename']) . "\n";
204 }
205
206 $file_id = fastdfs_storage_upload_by_filebuff1("this\000is\000a\000test.", "bin",
207		array('width'=>1024, 'height'=>768, 'font'=>'Aris'));
208 if (!$file_id)
209 {
210        echo "fastdfs_storage_upload_by_filebuff1 fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
211 }
212 else
213 {
214	$file_content = fastdfs_storage_download_file_to_buff1($file_id);
215	echo "file content: " . $file_content . "(" . strlen($file_content) . ")\n";
216 	$local_filename = 't2.txt';
217	echo 'storage_download_file_to_file1 result: ' .
218		fastdfs_storage_download_file_to_file1($file_id, $local_filename) . "\n";
219	echo "fastdfs_storage_set_metadata1 result: " . fastdfs_storage_set_metadata1(
220		$file_id, array('color'=>'yellow', 'size'=>'1234567890', 'font'=>'MS Serif'),
221		FDFS_STORAGE_SET_METADATA_FLAG_MERGE) . "\n";
222	$meta_list = fastdfs_storage_get_metadata1($file_id);
223	var_dump($meta_list);
224
225	$master_file_id = $file_id;
226	$prefix_name = '.part2';
227	$file_ext_name = 'txt';
228	$slave_file_id = fastdfs_storage_upload_slave_by_filebuff1('this is slave file1.',
229		$master_file_id, $prefix_name, $file_ext_name);
230	if ($slave_file_id !== false)
231	{
232	var_dump($slave_file_id);
233
234	$generated_file_id = fastdfs_gen_slave_filename($master_file_id, $prefix_name, $file_ext_name);
235	if ($slave_file_id != $generated_file_id)
236	{
237		echo "${slave_file_id}\n != \n${generated_file_id}\n";
238	}
239
240	echo "delete file $slave_file_id return: " . fastdfs_storage_delete_file1($slave_file_id) . "\n";
241	}
242        else
243        {
244                echo "fastdfs_storage_upload_slave_by_filebuff1 fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
245        }
246
247	echo "delete file $file_id return: " . fastdfs_storage_delete_file1($file_id) . "\n";
248 }
249
250
251 var_dump(fastdfs_tracker_query_storage_update($group_name, $remote_filename));
252 var_dump(fastdfs_tracker_query_storage_fetch($group_name, $remote_filename));
253 var_dump(fastdfs_tracker_query_storage_list($group_name, $remote_filename));
254 var_dump(fastdfs_tracker_query_storage_update1($file_id));
255 var_dump(fastdfs_tracker_query_storage_fetch1($file_id, $tracker));
256 var_dump(fastdfs_tracker_query_storage_list1($file_id, $tracker));
257
258 echo "fastdfs_tracker_close_all_connections result: " . fastdfs_tracker_close_all_connections() . "\n";
259 $fdfs = new FastDFS();
260 echo 'tracker_make_all_connections result: ' . $fdfs->tracker_make_all_connections() . "\n";
261 $tracker = $fdfs->tracker_get_connection();
262 var_dump($tracker);
263
264 $server = $fdfs->connect_server($tracker['ip_addr'], $tracker['port']);
265 var_dump($server);
266 var_dump($fdfs->disconnect_server($server));
267
268 var_dump($fdfs->tracker_query_storage_store_list());
269
270 //var_dump($fdfs->tracker_list_groups());
271 //var_dump($fdfs->tracker_query_storage_store());
272 //var_dump($fdfs->tracker_query_storage_update($group_name, $remote_filename));
273 //var_dump($fdfs->tracker_query_storage_fetch($group_name, $remote_filename));
274 //var_dump($fdfs->tracker_query_storage_list($group_name, $remote_filename));
275
276 var_dump($fdfs->tracker_query_storage_update1($file_id));
277 var_dump($fdfs->tracker_query_storage_fetch1($file_id));
278 var_dump($fdfs->tracker_query_storage_list1($file_id));
279
280 $file_info = $fdfs->storage_upload_by_filename("/usr/include/stdio.h");
281 if (!$file_info)
282 {
283      echo "storage_upload_by_filename fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
284 }
285 else
286 {
287	$group_name = $file_info['group_name'];
288	$remote_filename = $file_info['filename'];
289
290	var_dump($file_info);
291	var_dump($fdfs->get_file_info($group_name, $remote_filename));
292
293	$master_filename = $remote_filename;
294	$prefix_name = '.part1';
295	$slave_file_info = $fdfs->storage_upload_slave_by_filename("/usr/include/stdio.h",
296		$group_name, $master_filename, $prefix_name);
297        if ($slave_file_info !== false)
298        {
299        var_dump($slave_file_info);
300
301        $generated_filename = $fdfs->gen_slave_filename($master_filename, $prefix_name);
302        if ($slave_file_info['filename'] != $generated_filename)
303        {
304                echo "${slave_file_info['filename']}\n != \n${generated_filename}\n";
305        }
306
307        echo "delete slave file return: " . $fdfs->storage_delete_file($slave_file_info['group_name'], $slave_file_info['filename']) . "\n";
308        }
309        else
310        {
311                echo "storage_upload_slave_by_filename fail, errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
312        }
313
314	echo "delete file return: " . $fdfs->storage_delete_file($file_info['group_name'], $file_info['filename']) . "\n";
315 }
316
317 $file_ext_name = 'c';
318 $file_id = $fdfs->storage_upload_by_filename1("/usr/include/stdio.h", $file_ext_name, array('width'=>1024, 'height'=>800, 'font'=>'Aris'));
319 if (!$file_id)
320 {
321      echo "storage_upload_by_filename1 fail, errno: " . fastdfs_get_last_error_no() . ", error info: " . fastdfs_get_last_error_info() . "\n";
322 }
323 else
324 {
325	$master_file_id = $file_id;
326	$prefix_name = '.part2';
327	$slave_file_id = $fdfs->storage_upload_slave_by_filename1("/usr/include/stdio.h",
328		$master_file_id, $prefix_name, $file_ext_name);
329	if ($slave_file_id !== false)
330	{
331	var_dump($slave_file_id);
332
333	$generated_file_id = $fdfs->gen_slave_filename($master_file_id, $prefix_name, $file_ext_name);
334	if ($slave_file_id != $generated_file_id)
335	{
336		echo "${slave_file_id}\n != \n${generated_file_id}\n";
337	}
338
339	$result = $fdfs->storage_delete_file1($slave_file_id);
340	echo "delete file $slave_file_id return: $result\n";
341	}
342        else
343        {
344                echo "storage_upload_slave_by_filename1 fail, errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
345        }
346
347	echo "delete file $file_id return: " . $fdfs->storage_delete_file1($file_id) . "\n";
348 }
349
350 $file_info = $fdfs->storage_upload_by_filebuff("", "txt");
351 if ($file_info)
352 {
353	var_dump($file_info);
354	$file_content = $fdfs->storage_download_file_to_buff($file_info['group_name'], $file_info['filename']);
355	echo "file content: " . $file_content . "(" . strlen($file_content) . ")\n";
356 	$local_filename = 't3.txt';
357	echo 'storage_download_file_to_file result: ' .
358		$fdfs->storage_download_file_to_file($file_info['group_name'], $file_info['filename'], $local_filename) . "\n";
359
360	echo "storage_set_metadata result: " . $fdfs->storage_set_metadata(
361		$file_info['group_name'], $file_info['filename'],
362		array('color'=>'yellow', 'size'=>32), FDFS_STORAGE_SET_METADATA_FLAG_OVERWRITE) . "\n";
363
364	$meta_list = $fdfs->storage_get_metadata($file_info['group_name'], $file_info['filename']);
365	var_dump($meta_list);
366
367	$master_filename = $file_info['filename'];
368	$prefix_name = '.part1';
369	$file_ext_name = 'txt';
370	$slave_file_info = $fdfs->storage_upload_slave_by_filebuff('this is slave file  1 by class.',
371		$file_info['group_name'], $master_filename, $prefix_name, $file_ext_name);
372        if ($slave_file_info !== false)
373        {
374        var_dump($slave_file_info);
375
376        $generated_filename = $fdfs->gen_slave_filename($master_filename, $prefix_name, $file_ext_name);
377        if ($slave_file_info['filename'] != $generated_filename)
378        {
379                echo "${slave_file_info['filename']}\n != \n${generated_filename}\n";
380        }
381
382        echo "delete slave file return: " . $fdfs->storage_delete_file($slave_file_info['group_name'], $slave_file_info['filename']) . "\n";
383        }
384        else
385        {
386                echo "storage_upload_slave_by_filebuff fail, errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
387        }
388
389	echo "delete file return: " . $fdfs->storage_delete_file($file_info['group_name'], $file_info['filename']) . "\n";
390 }
391
392 $file_id = $fdfs->storage_upload_by_filebuff1("this\000is\001a\002test.", "bin",
393		array('color'=>'none', 'size'=>0, 'font'=>'Aris'));
394 if ($file_id)
395 {
396	var_dump($fdfs->get_file_info1($file_id));
397
398	$ts = time();
399	$token = $fdfs->http_gen_token($file_id, $ts);
400	echo "token=$token\n";
401
402	$file_content = $fdfs->storage_download_file_to_buff1($file_id);
403	echo "file content: " . $file_content . "(" . strlen($file_content) . ")\n";
404 	$local_filename = 't4.txt';
405	echo 'storage_download_file_to_file1 result: ' . $fdfs->storage_download_file_to_file1($file_id, $local_filename) . "\n";
406	echo "storage_set_metadata1 result: " . $fdfs->storage_set_metadata1(
407		$file_id, array('color'=>'yellow', 'size'=>32), FDFS_STORAGE_SET_METADATA_FLAG_MERGE) . "\n";
408
409	$master_file_id = $file_id;
410	$prefix_name = '.part2';
411	$file_ext_name = 'txt';
412	$slave_file_id = $fdfs->storage_upload_slave_by_filebuff1('this is slave file 2 by class.',
413		$master_file_id, $prefix_name, $file_ext_name);
414	if ($slave_file_id !== false)
415	{
416	var_dump($slave_file_id);
417
418	$generated_file_id = $fdfs->gen_slave_filename($master_file_id, $prefix_name, $file_ext_name);
419	if ($slave_file_id != $generated_file_id)
420	{
421		echo "${slave_file_id}\n != \n${generated_file_id}\n";
422	}
423
424	echo "delete file $slave_file_id return: " . $fdfs->storage_delete_file1($slave_file_id) . "\n";
425	}
426        else
427        {
428                echo "storage_upload_slave_by_filebuff1 fail, errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
429        }
430
431	$meta_list = $fdfs->storage_get_metadata1($file_id);
432	if ($meta_list !== false)
433	{
434		var_dump($meta_list);
435	}
436	else
437	{
438		echo "errno: " . $fdfs->get_last_error_no() . ", error info: " . $fdfs->get_last_error_info() . "\n";
439	}
440
441        echo "delete file $file_id return: " . $fdfs->storage_delete_file1($file_id) . "\n";
442 }
443
444 var_dump($fdfs->active_test($tracker));
445 echo 'tracker_close_all_connections result: ' . $fdfs->tracker_close_all_connections() . "\n";
446?>
447