Die Upload-Felder.
Schritt 0: make_form erweitern und Formularkodierung anpassen
Suche
default:
cpg_die(CRITICAL_ERROR, 'Invalid action for form creation ' . $element[0], __FILE__, __LINE__);
}
und füge darüber folgendes ein
case 'upload':
$value = $form_data[$element[1]];
if ($element[2]) {
echo <<< EOT
<tr>
<td width="40%" class="{$cellStyle}" height="25" valign="top">
{$element[2]}
</td>
<td width="60%" class="{$cellStyle}" valign="top">
<input type="file" style="width: 100%" name="{$element[1]}" class="listbox" />
</td>
</tr>
EOT;
}
break;
Suche
<form name="cpgform" id="cpgform" method="post" action="{$CPG_PHP_SELF}">
und ersetze es durch
<form name="cpgform" id="cpgform" method="post" action="{$CPG_PHP_SELF}" enctype="multipart/form-data">
Schritt 1: Frontend
Füge wie bereits beschrieben in der Nähe der anderen Zeilen mit
$edit_profile_form_param[]
etwas in folgender Art hinzu
$edit_profile_form_param[] = array('upload', 'custom_upload_1', 'Upload 1');
$edit_profile_form_param[] = array('upload', 'custom_upload_2', 'Upload 2');
Schritt 2: Backend
Jetzt beginnt der Teil, der evtl. nicht deinen Vorstellungen entspricht. Wenn das Formular abgesendet wird, werden entweder neue Bilder mitgesendet oder "nichts". Wenn nichts mitgesendet wird, wird das ggf. bereits hochgeladene Bild weiter verwendet. Wenn etwas mitgesendet wird und es ein Bild mit den korrekten Abmessungen ist, wird ab sofort dieses Bild verwendet. Wenn es kein Bild ist oder die falschen Abmessungen hat, wird das ggf. bereits hochgeladene Bild weiter verwendet. Ein Bild löschen ist erstmal nicht möglich, können wir später ggf. noch einbauen.
Damit Coppermine etwas mit den Erweiterungen anzufangen weiß, suchen wir
$profile6 = $superCage->post->getEscaped('user_profile6');
und fügen danach folgenden Code ein:
function custom_upload($custom_upload_x, $width, $height) {
global $CONFIG;
$superCage = Inspekt::makeSuperCage();
if ($superCage->files->getRaw("/{$custom_upload_x}/tmp_name") && is_image($superCage->files->getRaw("/{$custom_upload_x}/name"))) {
$uploaded_file = $CONFIG['fullpath'].$CONFIG['userpics'].'user_'.USER_ID.'_'.$custom_upload_x.'.png';
if (move_uploaded_file($superCage->files->getRaw("/{$custom_upload_x}/tmp_name"), $uploaded_file.'_tmp')) {
$imagesize = cpg_getimagesize($uploaded_file.'_tmp');
if ($imagesize[0] == $width && $imagesize[1] == $height) {
rename($uploaded_file.'_tmp', $uploaded_file);
} else {
unlink($uploaded_file.'_tmp');
}
}
}
}
custom_upload('custom_upload_1', 800, 300);
custom_upload('custom_upload_2', 350, 600);
Schritt 3: Daten im öffentlichen Profil anzeigen
Suche
if ($CONFIG['user_profile6_name'] != '') {
$display_profile_form_param[] = array('text', 'user_profile6', $CONFIG['user_profile6_name']);
}
unter füge darunter folgendes ein:
$display_profile_form_param[] = array('text', 'custom_upload_1', 'Upload 1');
$display_profile_form_param[] = array('text', 'custom_upload_2', 'Upload 2');
Suche
'user_profile6' => bb_decode($user_data['user_profile6']),
und füge darunter folgendes ein:
'custom_upload_1' => custom_image('custom_upload_1'),
'custom_upload_2' => custom_image('custom_upload_2'),
Jetzt fügst du vor dem darüberstehenden
$form_data = array(
noch folgende Funktion hinzu:
function custom_image($img) {
global $CONFIG;
$superCage = Inspekt::makeSuperCage();
$user_id = $superCage->get->getInt('uid');
$img = $CONFIG['fullpath'].$CONFIG['userpics'].'user_'.$user_id.'_'.$img.'.png';
if (file_exists($img)) {
return "<img class=\"image\" src=\"{$img}\" />";
} else {
return false;
}
}