korrekt, panicsheep
da der Post nun länger wird, hab ich das nun auch flux mal gemacht.
blacktiger, hier ne Anleitung wie du das hinbekommst in 3 schritten.
Achtung: Ich kann kein PHP, also keine Garantie das dies hier perfekter Code ist. Ich übernehm auch keine Haftung falls irgendwas danach nicht mehr funktionieren sollte.
Gerne dürfen sich die PHP-Cracks da dran setzen und diesen verbessern!
Schritt1: Datei galleryup.htm
----------------------------
Erstelle eine Datei "galleryup.htm" in dem Ordner /include/templates/
Die Datei sollte folgenden Inhalt haben:
<script language="JavaScript" type="text/javascript">
<!--
function change_txt ( img ) {
var x = prompt ( "Bitte die neue Beschreibung für "+img+" eingeben", "");
if ( x ) {
document.location.href="?m=gallery&um=chtxt&txt="+x+"&img="+img;
}
}
//-->
</script>
<table width="100%" cellpadding="10" class="dark">
<tr class="Callg">
<td valign="top">
<form action="?m=galleryup&um=addimg" method="POST" enctype="multipart/form-data">
<table cellpadding="3" cellspacing="1" border="0" class="border">
<tr class="Chead">
<td colspan="2"><b>Ein Bild hochladen</b></td>
</tr><tr>
<td class="Cmite">Bild</td>
<td class="Cnorm"><input type="file" name="file"></td>
</tr><tr>
<td class="Cmite">Kategorie</td>
<td class="Cnorm"><select name="dir">{_list_dirs@<option>%1</option>}</select></td>
</tr><tr>
<td class="Cmite">Beschreibung</td>
<td class="Cnorm"><input type="text" name="besch" size="40"></td>
</tr><tr class="Cdark">
<td></td>
<td><input type="submit" value="Hochladen"></td>
</tr>
</table>
</form>
</td>
</table>
Schritt2: Datei galleryup.php
-----------------------------
Das ist nun etwas kniffliger, da ich hier einige spezifische Änderungen für mich gemacht habe, die du u.U. abändern willst.
Erstelle eine Datei galleryup.php im Ordner /include/ mit dem folgenden Inhalt:
<?php
# Copyright by: Manuel
# Support: www.ilch.de
# modified by rom
defined ('main') or die ( 'no direct access' );
# Benutzer ist berechtigt?
if ( $_SESSION['authright'] <= -2 ) {
$title = $allgAr['title'].' :: Bild hochladen';
$hmenu = 'Bild hochladen';
$design = new design ( $title , $hmenu );
$design->header();
if ( !is_writable ( 'include/images/gallery' ) ) {
die ('<b>Fehler</b> Das Verzeichnis include/images/<u>gallery</u> hat keine Schreibrechte!! bitte nachholen!' );
}
$show = true;
function create_thumb ( $imgpath, $thumbpath ) {
global $allgAr;
$neueBreite = $allgAr['gallery_preview_width'];
$size=getimagesize($imgpath);
$breite=$size[0];
$hoehe=$size[1];
$neueHoehe=intval($hoehe*$neueBreite/$breite);
if ($size[2] == 2) { # JPG
/*
evtl. besser.... ?! oje kein bock zu testen
$thumb = imagecreate ($width, $height);
imageJPEG($thumb,"images/temp.jpg");
$thumb = @imagecreatefromjpeg("images/temp.jpg");
to check if funktion exists
ob_start();
phpinfo(8);
$phpinfo=ob_get_contents();
ob_end_clean();
$phpinfo=strip_tags($phpinfo);
$phpinfo=stristr($phpinfo,"gd version");
$phpinfo=stristr($phpinfo,"version");
$end=strpos($phpinfo,".");
$phpinfo=substr($phpinfo,0,$end);
$length = strlen($phpinfo)-1;
$phpinfo=substr($phpinfo,$length);
if($phpinfo<2){
$dst_img=ImageCreate($new_w,$new_h);}
else {
$dst_img=ImageCreateTrueColor($new_w,$new_h);
}
?>
*/
$altesBild=ImageCreateFromJPEG($imgpath);
$neuesBild=imageCreate($neueBreite,$neueHoehe);
imageCopyResized($neuesBild,$altesBild,0,0,0,0,$neueBreite,$neueHoehe,$breite,$hoehe);
ImageJPEG($neuesBild,$thumbpath);
} elseif ($size[2] == 3) { # PNG
$altesBild=ImageCreateFromPNG($imgpath);
$neuesBild=imageCreate($neueBreite,$neueHoehe);
imageCopyResized($neuesBild,$altesBild,0,0,0,0,$neueBreite,$neueHoehe,$breite,$hoehe);
ImagePNG($neuesBild,$thumbpath);
}
}
switch ( $um ) {
case 'addimg' :
$img = $_FILES['file']['name'];
if ( strpos ( $img, '_' ) === FALSE AND strpos ( $img, '.' ) === FALSE ) {
echo 'Konnte Bild nicht hochladen, weil der Name einen <b>.</b> (Punkt) oder einen <b>_</b> (Unterstrich) enthalten hat.<br />';
} else {
$imgpath = 'include/images/gallery/'.$_POST['dir'].'_'.$_FILES['file']['name'];
if (move_uploaded_file ( $_FILES['file']['tmp_name'] , $imgpath ) ) {
$tmp = explode('.',$_FILES['file']['name']);
if (function_exists('imageCopyResized')) {
$thumbpath = 'include/images/gallery/'.$_POST['dir'].'_'.$tmp[0].'_small.'.$tmp[1];
create_thumb ( $imgpath, $thumbpath );
}
if ( !empty($_POST['besch']) ) {
$datei = fopen('include/images/gallery/'.$_POST['dir'].'_'.$tmp[0].'.txt', "w");
fputs($datei, $_POST['besch']);
fclose($datei);
}
}
echo '<center><b>Bild erfolgreich hochgeladen!</center>';}
break;
case 'deldir' :
$category = $_GET['dir'];
$o = opendir('include/images/gallery');
$category_length = strlen ( $category );
while ($f = readdir ($o)) {
if($f != '.' && $f != '..' AND substr ( $f , 0, $category_length ) == $category AND strpos ($f, '.') !== FALSE) {
unlink ( 'include/images/gallery/'.$f );
}
}
unlink ('./include/images/gallery/'.$category);
break;
case 'adddir' :
$dir = $_POST['dir'];
if ( strpos ( $dir, '_' ) === FALSE AND strpos ( $dir, '.' ) === FALSE ) {
fopen ( './include/images/gallery/'.$_POST['dir'], 'a');
} else {
echo 'Konnte Category nicht anlegen, weil der Name einen <b>.</b> (Punkt) oder einen <b>_</b> (Unterstrich) enthalten hat.<br />';
}
break;
case 'chtxt' :
$tmp = explode('.',$_GET['img']);
$datei = fopen('./include/images/gallery/'.$tmp[0].'.txt', "w");
fputs($datei, $_GET['txt']);
fclose($datei);
break;
case 'delimg' :
$tmp = explode('.',$_GET['img']);
unlink('include/images/gallery/'.$_GET['img']);
if ( file_exists ( 'include/images/gallery/'.$tmp[0].'.txt' ) ) {
unlink('include/images/gallery/'.$tmp[0].'.txt');
}
unlink('include/images/gallery/'.$tmp[0].'_small.'.$tmp[1]);
break;
case 'neuthumbs' :
$o = opendir('include/images/gallery');
while ($f = readdir ($o)) {
if($f != '.' && $f != '..' AND strpos ($f, '.') !== FALSE AND strpos ($f, '_small.') === FALSE AND strpos ($f, '.txt') === FALSE) {
$tmp = explode('.',$f);
if (function_exists('imageCopyResized')) {
$thumbpath = 'include/images/gallery/'.$tmp[0].'_small.'.$tmp[1];
$imgpath = 'include/images/gallery/'.$f;
if ( $_POST['overwrite'] == 'yes' OR !file_exists($thumbpath)) {
create_thumb ( $imgpath, $thumbpath );
}
}
}
}
closedir($o);
break;
}
if ( $show ) {
$tpl = new tpl ( 'galleryup.htm' );
$ordner = array();
$o = opendir('include/images/gallery');
$dirs = '';
while ($f = readdir ($o)) {
if($f != '.' && $f != '..' AND strpos ($f, '.') === FALSE) {
$dirs .= $tpl->list_get('dirs',array($f));
$ordner[] = $f;
}
}
closedir($o);
$tpl->set_out('dirs',$dirs,0);
foreach($ordner as $category) {
$tpl->set_out('category',$category,1);
$o = opendir('include/images/gallery');
$category_length = strlen ( $category );
$class = 'Cnorm';
while ($f = readdir ($o)) {
if($f != '.' && $f != '..' AND substr ( $f , 0, $category_length ) == $category AND strpos ($f, '.') !== FALSE AND strpos ($f, '_small.') === FALSE AND strpos ($f, '.txt') === FALSE) {
$tmp = explode('_',$f);
$class = ( $class == 'Cmite' ? 'Cnorm' : 'Cmite' );
$ar = array (
'img' => $tmp[1],
'deimg' => $f,
'class' => $class
);
$tpl->set_ar_out($ar,2);
}
}
closedir($o);
}
$tpl->out(3);
}
//-----------------------------------------------------------|
$design->footer();
} else {
die ( 'no access' );
}
?>
Bitte beachte die Zeile am Anfang
if ( $_SESSION['authright'] <= -2 ) {
sowie die Zeilen am Ende
} else { die ( 'no access' ); }
Bei mir dürfen keine Benutzer, die sich nur registriert haben (-1), Bilder hochladen.
Erst nachdem ich die Benutzer auf einen Status höher (-2) "befördert" habe, sollen sie Bilder hochladen können.
Ändere also die authright-Zahl entsprechend deinem Bedürfnis ab...
Schritt3: Einbindung in die Hauptseite
--------------------------------
Hier biete ich dir 2 Möglichkeiten.
1. Einbindung als Menülink:
Einfach im Admin die neue Seite galleryup.php als Menülink in dein Hauptmenü einbinden. Setze hier die gleichen Berechtigungen auf den Menülink, welche du als "Ziffer" in die php-Datei galleryup.php eingetragen hast (s.o.).
2. Einbindung in die Gallery:
Diese Lösung habe ich verwendet, sie erfordert aber die Veränderung der Datei /include/gallery.php.
Öffne also die Datei /include/gallery.php mit einem Text Editor (empfehlung: Crimson Editor) und ändere ab Zeile 46 den Code ab.
Vorher:
closedir($o);
$tpl->out(2);
$design->footer();
break;
case 'showcat' :
Nachher:
closedir($o);
$tpl->out(2);
if ( $_SESSION['authright'] <= -2 )
{ echo '<br><br><a href="http://deinedomain.de/index.php?m=galleryup"><b>Eigenes Bild hochladen</b></a>';
$design->footer();
break;
}
else
{ $design->footer();
break; }
case 'showcat' :
Bitte beachte auch hier, das nach der Editierung nur Benutzer der Berechtigungsstufe "-2" hochladen können. Ändere also auch hier die "-2" in eine Stufe einer Wahl ab.
Ausserdem ändere noch den Text von "http://deinedomain.de/index.php" ab zu der Domain deiner Webseite.
Zuletzt geändert von rom am 07.06.2005 - 13:04