INPUT:
Code: Alles auswählen
?>
<table cellspacing="0" cellpadding="0" cellpadding="4">
<tr>
<td style="font-size:11px">Upload-Verzeichnis:</td>
<td>
<select name="CMS_VAR[0]">
<option value="0"></option>
<?php
$sql = "SELECT DISTINCT dirname from ".$cfg["tab"]["upl"];
$db->query($sql);
while ( $db->next_record() ) {
$upload_dir=substr_replace($db->f("dirname"),'',(strlen($db->f("dirname"))-1));
if ( "CMS_VALUE[0]" == $upload_dir) {
echo '<option selected="selected" value="'.$upload_dir.'">'.$db->f("dirname").'</option>';
} else {
echo '<option value="'.$upload_dir.'">'.$db->f("dirname").'</option>';
}
}
?>
</select>
</td>
</tr>
<tr>
<td style="font-size:11px">Datei-Typ(en):</td>
<td><input type="text" name="CMS_VAR[1]" value="CMS_VALUE[1]"></td>
</tr>
<tr>
<td style="font-size:11px" colspan ="2">Erlaubte Datei-Typ(en) mit einem | trennen. Bsp.: gif|jpg|pdf</td>
</tr>
<tr>
<td style="font-size:11px">maximale Größe:</td>
<td><input type="text" name="CMS_VAR[2]" value="CMS_VALUE[2]"> KB</td>
</tr>
<tr>
<td style="font-size:11px" colspan ="2">1000 KB entsprechen 1 MB</td>
</tr>
</table>
<?php
Code: Alles auswählen
<?php
cInclude('includes', 'functions.upl.php');
// Absoluter Pfad zum Ordner in den die Datei hochgeladen werden soll.
$pfad = "upload/CMS_VALUE[0]";
// Ist eine maximale Größe der Datei festgelegt worden ?
if ("CMS_VALUE[2]" == "") {
$sizeabfrage = "no";
}
else {
$sizeabfrage = "yes";
}
// Maximale Größe der Datei (Falls $sizeabfrage = "yes" ist)
$filesize = "CMS_VALUE[2]"*1.024*1024;
// Wird die maximale Größe auch angezeigt ?
if ("CMS_VALUE[2]" == "") {
$sizeanzeige = "no";
}
else {
$sizeanzeige = "yes";
}
// Was für Dateitypen sollen erlaubt sein ?
$extend = "CMS_VALUE[1]";
// Sollen die erlaubten Dateitypen angezeigt werden ?
$extendanzeige = "yes";
$fehler = FALSE;
if ($senden) {
if ($file_name == "") {
$desc = $Beschreibung;
echo "<font color=#FF0000><b>Es wurde keine Datei ausgewählt!</b></font>";
$fehler = TRUE;
}
if (!$fehler)
if (file_exists("$pfad/$file_name")) {
$desc = $Beschreibung;
echo "<font color=#FF0000><b>Dateiname schon vorhanden!</b></font>";
$fehler = TRUE;
}
if (!$fehler)
if ($sizeabfrage == "yes") {
if ($file_size > $filesize) {
$desc = $Beschreibung;
echo "<font color=#FF0000><b>Die Datei ist zu groß!</b></font>";
$fehler = TRUE;
}
}
if (!$fehler)
if (!eregi("($extend)$", $file_name)) {
$desc = $Beschreibung;
echo "<font color=#FF0000><b>Dieser Dateityp ist nicht erlaubt!</b></font>";
$fehler = TRUE;
}
if (!$fehler) {
if (copy($file, $pfad."/".$file_name)) {
uplSyncDirectory("CMS_VALUE[0]"."/");
$db = new DB_Contenido;
$sql = 'SELECT * FROM `con_upl` WHERE `filename` = "'.$file_name.'" LIMIT 0, 30';
$db->query($sql);
$db->next_record();
$ID = $db->f('idupl');
$sql = 'UPDATE `con_upl` SET `description` = "'.$Beschreibung.'" WHERE `idupl` = "'.$ID.'"';
$db->query($sql);
echo "<font color=#00FF00><b>Datei hochgeladen</b></font><BR>";
$fehler = FALSE;
}
else {
echo "<font color=#FF0000><b>Datei nicht hochgeladen</b></font>";
$desc = $Beschreibung;
$fehler = TRUE;
}
}
}
if ($fehler || !$senden) {
?>
<table>
<form action="<?php $PHP_SELF; ?>" method="post" enctype="multipart/form-data">
<BR>
<b>Bitte Datei auswählen:</b>
<BR>
<?php
if ($sizeanzeige == "yes") {
echo ("Maximale Größe: ".($filesize/1024/1024)." MB");
}
?>
<BR>
<?php
if ($extendanzeige == "yes") {
echo ("Erlaubte Dateitypen: ".str_replace("|",", ",$extend));
}
?>
<BR><BR>
<input type="file" size="40" name="file">
<BR>
<b>Beschreibung</b> (optional):<br>
<textarea name="Beschreibung" wrap="virtual" rows="5" cols="60" maxlength="10"><?php echo $desc; ?></textarea>
<BR><BR>
<input type="Submit" name="senden" value="Hochladen"><br>
</form>
</table>
<?php
}
?>
Hier noch der Code für eine zugehörige Downloadliste mit MouseOver-Effekt auf den Tabellen-Zeilen und ein- und ausblendbarer Beschreibung zum jeweiligen Download.
INPUT:
Code: Alles auswählen
?>
<table cellspacing="0" cellpadding="0" cellpadding="4">
<tr>
<td style="font-size:11px">Download-Verzeichnis:</td>
<td>
<select name="CMS_VAR[0]">
<option value="0"></option>
<?php
$sql = "SELECT DISTINCT dirname from ".$cfg["tab"]["upl"];
$db->query($sql);
while ( $db->next_record() ) {
$upload_dir=substr_replace($db->f("dirname"),'',(strlen($db->f("dirname"))-1));
if ( "CMS_VALUE[0]" == $upload_dir) {
echo '<option selected="selected" value="'.$upload_dir.'">'.$db->f("dirname").'</option>';
} else {
echo '<option value="'.$upload_dir.'">'.$db->f("dirname").'</option>';
}
}
?>
</select>
</td>
</tr>
<tr>
<td style="font-size:11px">Datei-Typ:</td>
<td>
<select name="CMS_VAR[1]">
<option value="0"></option>
<?php
$sql = "SELECT DISTINCT filetype from ".$cfg["tab"]["upl"]; //." WHERE dirname='CMS_VALUE[0]/'";
$db->query($sql);
while ( $db->next_record() ) {
$upload_file=$db->f("filetype");
if ( "CMS_VALUE[1]" == $upload_file) {
echo '<option selected="selected" value="'.$upload_file.'">'.$db->f("filetype").'</option>';
} else {
echo '<option value="'.$upload_file.'">'.$db->f("filetype").'</option>';
}
}
?>
</select>
</td>
</tr>
</table>
<?php
Code: Alles auswählen
<?php
//Download-Verzeichnis wird synchronisiert
cInclude('includes', 'functions.upl.php');
uplSyncDirectory("CMS_VALUE[0]"."/");
?>
<script language="javascript">
<!--
function setFrame(theRow,thePointerColor,theBackgroundColor,cells)
{
if (!cells) cells=0;
if (thePointerColor == '' || typeof(theRow.style) == 'undefined') return false;
if (typeof(document.getElementsByTagName) != 'undefined') {
var theCells = theRow.getElementsByTagName('td');
} else if (typeof(theRow.cells) != 'undefined') {
var theCells = theRow.cells;
} else {
return false;
}
var rowCellsCnt = theCells.length;
var number = rowCellsCnt-cells;
for (var c = 0; c < number; c++) {
if (c==0) theCells[c].style.borderLeft = "solid";
if (c==(number-1)) theCells[c].style.borderRight = "solid";
theCells[c].style.borderTop = "solid";
theCells[c].style.borderBottom = "solid";
theCells[c].style.borderWidth = "1px";
theCells[c].style.backgroundColor = theBackgroundColor;
theCells[c].style.borderColor = thePointerColor;
<!--theCells[c].style.cursor = "pointer";-->
}
return true;
}
// -->
</script>
<script type="text/javascript">
function show (ID) {
var test;
test = document.form.hidden.value;
if (document.getElementById) {
if (document.getElementById(ID).style.visibility == "hidden") {
document.getElementById(ID).style.visibility = "visible";
document.getElementById(ID).style.position = "relative";
}
else {
document.getElementById(ID).style.visibility = "hidden";
document.getElementById(ID).style.position = "absolute";
}
}
if (test != "") {
if (test != ID) {
if (document.getElementById(test).style.visibility == "visible") {
document.getElementById(test).style.visibility = "hidden";
document.getElementById(test).style.position = "absolute";
}
}
}
document.form.hidden.value = ID;
}
</script>
<?php
//Datenbankanfrage wird definiert (was, wo und wie sortiert)
$sql = "SELECT * FROM ".$cfg["tab"]["upl"]." WHERE dirname ='CMS_VALUE[0]/' order by filetype,filename asc";
//Verbindung zur Datenbank wird hergestellt
$db->query($sql);
//Zeigt die Datensätze in der Tabelle an
echo '<span class="filecount">Insgesamt stehen ' . $db ->num_rows() . ' Dokumente zur Verfügung:</span><br>';
//Link zur Datei im Upload-Verzeichnis
$href = $cfgClient[$client]["htmlpath"]["frontend"] . $cfgClient[$client]["upload"];
$i = 1;
//Die Datensätze werden in einer Aufzählungsliste widergegeben, die sich über die CSS-Klasse 'ul.download' gestaltem lässt
echo "<table width=\"480\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">";
echo "
<tr>
<td colspan=\"3\"> </td>
</tr>
";
while ($db->next_record())
{
$dateityp = $db->f("filetype");
echo "
<tr onmouseover=\"setFrame(this, '#CCCCCC', '#EFEFEF')\" onmouseout=\"setFrame(this, '#FFFFFF', '#FFFFFF')\">
<td style=\"border-top:solid 1px #FFFFFF;border-bottom:solid 1px #FFFFFF;border-left:solid 1px #FFFFFF;cursor:pointer;\" width=\"20\" valign=\"top\" onClick=\"javascript:show('".$db->f("idupl")."')\"><img src=\"".$cfgClient[$client]['htmlpath']['frontend']."images/filetypes/".$dateityp.".gif\"></td>
<td style=\"border-top:solid 1px #FFFFFF;border-bottom:solid 1px #FFFFFF;cursor:pointer;\" width=\"380\" valign=\"top\" onClick=\"javascript:show('".$db->f("idupl")."')\"><a title=\"download ".$db->f("filename")."\" target=\"_blank\" href=\"".$href.$db->f("dirname").$db->f("filename")."\" onClick=\"this.blur()\">".$db->f("filename")."</a><div id=\"".$db->f("idupl")."\" style=\"position:absolute; visibility:hidden\">Beschreibung: ";
if ($db->f("description") != "") {
echo $db->f("description");
}
else {
echo "keine Beschreibung vorhanden";
}
echo "</div></td>
<td style=\"border-top:solid 1px #FFFFFF;border-bottom:solid 1px #FFFFFF;border-right:solid 1px #FFFFFF;cursor:pointer;\" width=\"80\" valign=\"top\" align=\"right\" onClick=\"javascript:show('".$db->f("idupl")."')\"><span class=\"fileattrib\"> [".round($db->f("size")/1024,1)." KB]</span></td>
</tr>
";
$i++;
}
echo "</table>";
echo '<br><br>Um eine Datei herunterzuladen, klicken Sie bitte mit der rechten Maustaste auf den entsprechenden Dateinamen und wählen Sie im Kontextmenü "Ziel speichern unter..." aus.';
echo "<form name=\"form\" action=\"\"><input type=\"hidden\" id=\"hidden\" name=\"hidden\" value=\"\"></form>";
?>
Evtl. muss das Verzeichnis contenido/images/filetypes/ nach cms/images/ kopiert oder entsprechend der Code angepasst werden.
Bemerkung: Ich habe das ganze bisher nur auf einem lokalen System getestet. Der Code ist vielleicht stellenweise etwas spartanisch, funktioniert aber einwandfrei. Contenido-Version 4.5.2
Viel Spaß damit.