1 |
<?php |
2 |
/** |
3 |
* This file contains the FileUpload FormElement class. |
4 |
* |
5 |
* $Id: FEFile.inc,v 1.1 2003/04/17 06:07:16 hemna Exp $ |
6 |
* |
7 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
8 |
* @author Dave Brondsema <dave@brondsema.net> |
9 |
* @package phpHtmlLib |
10 |
* @subpackage FormProcessing |
11 |
* |
12 |
* @copyright LGPL - See LICENCE |
13 |
* |
14 |
*/ |
15 |
|
16 |
/** |
17 |
* This is the FileUpload FormElement which builds a |
18 |
* input field of type="file". |
19 |
* |
20 |
* @author Dave Brondsema <dave@brondsema.net> |
21 |
* @package phpHtmlLib |
22 |
* @subpackage FormProcessing |
23 |
* |
24 |
* @copyright LGPL - See LICENCE |
25 |
*/ |
26 |
class FEFile extends FEText { |
27 |
|
28 |
/** |
29 |
* This function builds and returns the |
30 |
* form element object |
31 |
* |
32 |
* @return object |
33 |
*/ |
34 |
function get_element() { |
35 |
|
36 |
$attributes = $this->_build_element_attributes(); |
37 |
$attributes["type"] = "file"; |
38 |
|
39 |
if (($value = $this->get_value()) != NULL) |
40 |
$attributes["value"] = $value; |
41 |
|
42 |
$tag = new INPUTtag($attributes); |
43 |
|
44 |
return $tag; |
45 |
} |
46 |
|
47 |
/** |
48 |
* This method validates the data |
49 |
* for this Form Element. |
50 |
* |
51 |
* It validates file size and partial uploads.. |
52 |
* @param FormValidation object. |
53 |
*/ |
54 |
function validate(&$_FormValidation) { |
55 |
switch ($_FILES[$this->get_element_name()]['error']) |
56 |
{ |
57 |
case 0: |
58 |
if ($_FILES[$this->get_element_name()]['size'] == 0) { |
59 |
$this->set_error_message("The uploaded file was empty."); |
60 |
return FALSE; |
61 |
} |
62 |
break; |
63 |
case 1: |
64 |
$this->set_error_message("The uploaded file exceeds the maximum file size, " . ini_get("upload_max_filesize")); |
65 |
return FALSE; |
66 |
break; |
67 |
case 2: |
68 |
$this->set_error_message("The uploaded file exceeds the maximum file size, " . $_REQUEST['MAX_FILE_SIZE'] . " bytes, specified for this form."); |
69 |
return FALSE; |
70 |
break; |
71 |
case 3: |
72 |
$this->set_error_message("The uploaded file was only partially uploaded."); |
73 |
return FALSE; |
74 |
break; |
75 |
case 4: |
76 |
$this->set_error_message("No file was uploaded."); |
77 |
return FALSE; |
78 |
break; |
79 |
case 5: |
80 |
$this->set_error_message("The uploaded file was empty."); |
81 |
return FALSE; |
82 |
break; |
83 |
} |
84 |
|
85 |
return TRUE; |
86 |
} |
87 |
|
88 |
/** |
89 |
* This function will return the |
90 |
* elements value |
91 |
* |
92 |
* @return mixed |
93 |
*/ |
94 |
function get_value() { |
95 |
return @$_FILES[$this->get_element_name()]['name']; |
96 |
} |
97 |
|
98 |
|
99 |
/** |
100 |
* This function will return this file's portion of the $_FILES array |
101 |
* |
102 |
* @return array |
103 |
*/ |
104 |
function get_file_info() { |
105 |
return $_FILES[$this->get_element_name()]; |
106 |
} |
107 |
|
108 |
} |