/ www / include /
/www/include/lib.php.inc
1 <?php
2 /* Copyright (C) 2012 The Meme Factory, Inc. http://www.meme.com/
3 * Copyright (C) 2006, 2008, Karl O. Pinc <kop@meme.com>
4 *
5 * This file is part of Gombe-MI.
6 *
7 * Gombe-MI is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Gombe-MI. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Library of php functions for Gombe-MI.
21 *
22 * Karl O. Pinc <kop@meme.com>
23 */
24
25 // Constants
26
27 //
28 // Functions.
29 //
30
31 /////////////////////////////////////////////////////////////////////
32 function move_and_fix_eol($from_path, $to_path) {
33 /* Move a file, converting Windoze and mac eol sequences to Unix eol.
34 *
35 * Input:
36 * $from_path Pathname to move
37 * $to_path Place to move to.
38 *
39 * Returns: system return code of exec() which copies.
40 * (0 on success, something else on failure)
41 *
42 * Side Effects: moves file
43 *
44 * Bugs:
45 */
46
47 exec("sed -e '" . 's/\r$//' . "' $from_path"
48 . ' | tr "\\r" "\\n"'
49 . " > $to_path"
50 , $dummy
51 , $result);
52
53 unlink($from_path);
54
55 return $result;
56 }
57
58 /////////////////////////////////////////////////////////////////////
59 function explain_error($f, $e) {
60 /*
61 * Explain an error code returned by $_FILE[]['error']
62 *
63 * Input:
64 * $f The description of the file to show to the user.
65 * $e The error code
66 *
67 * Returns: String containing html which explains the error.
68 *
69 * Side Effects: none
70 */
71
72 $e = "<p> $f: ";
73
74 switch ($e) {
75 case UPLOAD_ERR_OK:
76 $e .= "There is no error, the file uploaded with success.";
77 break;
78
79 case UPLOAD_ERR_INI_SIZE:
80
81 $e .= "<em class=\"error\">The uploaded file exceeds the upload_max_filesize directive in php.ini.</em>";
82 break;
83
84 case UPLOAD_ERR_FORM_SIZE:
85 $e .= "<em class=\"error\">The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.</em>";
86 break;
87
88 case UPLOAD_ERR_PARTIAL:
89 $e .= "<em class=\"error\">The uploaded file was only partially uploaded.</em>";
90 break;
91
92 case UPLOAD_ERR_NO_FILE:
93 $e .= "<em class=\"error\">No file was uploaded.</em>";
94 break;
95
96 }
97
98 $e .= "</p>";
99
100 return $e;
101 }
102