|
9 | 9 |
|
10 | 10 | if (isset($_POST["dn"]) and $_POST["dn"]) { |
11 | 11 | $action = "updateentry"; |
| 12 | + if (isset($_FILES['photo'])) { |
| 13 | + $action = "updatephoto"; |
| 14 | + } |
12 | 15 | } |
13 | 16 |
|
14 | 17 | if (!$dn) { |
@@ -110,6 +113,51 @@ function ($matches) use ($item, $update_attributes, $attributes_map) { |
110 | 113 | } |
111 | 114 | } |
112 | 115 |
|
| 116 | + # Update photo |
| 117 | + if ($action == "updatephoto") { |
| 118 | + if ( $_FILES['photo']['error'] ) { |
| 119 | + switch( $_FILES['photo']['error']) { |
| 120 | + case 1: |
| 121 | + case 2: |
| 122 | + $result = "phototoobig"; |
| 123 | + break; |
| 124 | + case 4: |
| 125 | + $result = "nophoto"; |
| 126 | + break; |
| 127 | + default: |
| 128 | + $result = "photonotuploaded"; |
| 129 | + } |
| 130 | + error_log("Upload photo for $dn failed with error $result (error code ".$_FILES['photo']['error'].")"); |
| 131 | + $action = "displayform"; |
| 132 | + } elseif (isset($update_photo_maxsize) and (filesize($_FILES['photo']['tmp_name']) >= $update_photo_maxsize)) { |
| 133 | + $result = "phototoobig"; |
| 134 | + $action = "displayform"; |
| 135 | + } else { |
| 136 | + |
| 137 | + if ($update_photo_ldap) { |
| 138 | + $update_attributes = array($photo_ldap_attribute => file_get_contents($_FILES['photo']['tmp_name'])); |
| 139 | + if (!ldap_mod_replace($ldap, $dn, $update_attributes)) { |
| 140 | + $result = "photonotuploaded"; |
| 141 | + $action = "displayform"; |
| 142 | + } else { |
| 143 | + $action = "displayentry"; |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + if ($update_photo_directory) { |
| 148 | + $search = ldap_read($ldap, $dn, '(objectClass=*)', array($photo_local_ldap_attribute)); |
| 149 | + $entry = ldap_get_entries($ldap, $search); |
| 150 | + $photo_name = $entry[0][$photo_local_ldap_attribute][0]; |
| 151 | + if (!move_uploaded_file($_FILES['photo']['tmp_name'], $photo_local_directory . $photo_name . $photo_local_extension )) { |
| 152 | + $result = "photonotuploaded"; |
| 153 | + $action = "displayform"; |
| 154 | + } else { |
| 155 | + $action = "displayentry"; |
| 156 | + } |
| 157 | + } |
| 158 | + } |
| 159 | + } |
| 160 | + |
113 | 161 | # Display form |
114 | 162 | if ($action == "displayform") { |
115 | 163 |
|
|
0 commit comments