login/edit: treat avatar as jpeg images
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 16 Jun 2018 13:05:49 +0000 (15:05 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 16 Jun 2018 19:58:28 +0000 (21:58 +0200)
login/edit.php

index bb2278faf2b02f22250656a9b6f2158d8329111a..e44d0597f6ea54147758f5ebcba6c01a2e525d2c 100644 (file)
@@ -22,9 +22,10 @@ $cols = [
 ];
 
 foreach ($cols as $col => &$colconf) {
-       $colpath = "{$user['dir']}/$col.txt";
+       $filetype = @$colconf['type'] == 'file' ? 'jpg' : 'txt';
+       $colpath = "{$user['dir']}/$col.$filetype";
        if (file_exists($colpath)) {
-               $colconf['value'] = @$colconf['type'] == 'file' ? '' :
+               $colconf['value'] = $filetype != 'txt' ? '' :
                        file_get_contents($colpath);
        }
        if (file_exists($user['dir']) and !is_writable($user['dir'])) {
@@ -112,6 +113,9 @@ if ($_POST) {
 foreach ($cols as $col => &$colconf) {
        print "\t";
        printf('<label for="%s">%s:</label> ', $col, ucfirst($colconf['label']));
+       if (@$colconf['type'] == 'file' and isset($colconf['value'])) {
+               printf('<img src="/%s" /><br />', $colconf['target']);
+       }
        print "<input";
        if (empty($colconf['target'])) print ' readonly';
        printf(' type="%s" name="%s" id="%1$s" value="%s"',
@@ -119,6 +123,9 @@ foreach ($cols as $col => &$colconf) {
                $col,
                htmlspecialchars(@$colconf['value'])
        );
+       if (@$colconf['type'] == 'file') {
+               printf(' accept="%s"', 'image/jpeg');
+       }
        print ' placeholder="Niet ingesteld"';
        print " />";