<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Homepage - Zubehör, Tipps und Tricks</title>
	<atom:link href="http://www.homepage-hilfe.org/feed" rel="self" type="application/rss+xml" />
	<link>http://www.homepage-hilfe.org</link>
	<description>Tutorials, Tipps und Tricks, Codesnippets hauptsächlich für CSS und PHP</description>
	<pubDate>Sun, 27 Jul 2008 22:27:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>PHP Uploadscript Tutorial</title>
		<link>http://www.homepage-hilfe.org/php-uploadscript-tutorial</link>
		<comments>http://www.homepage-hilfe.org/php-uploadscript-tutorial#comments</comments>
		<pubDate>Mon, 09 Jun 2008 18:22:55 +0000</pubDate>
		<dc:creator>Leichti</dc:creator>
		
		<category><![CDATA[PHP Tipps und Tricks]]></category>

		<category><![CDATA[Dateien]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[tutorial]]></category>

		<category><![CDATA[Uploadscript]]></category>

		<guid isPermaLink="false">http://www.homepage-hilfe.org/?p=26</guid>
		<description><![CDATA[Da ich mich in letzter Zeit ein bisschen mit diesem Thema befasst habe, habe ich ein kleines Tutorial zum Thema PHP Uploadscript geschrieben. Ziel ist es, Dateien aus dem Browser direkt in ein Verzeichnis zu laden. Auch sollen die hochzuladenden Dateitypen in unserem Uploadscript beschränkbar sein da dies eine gravierende Sicherheitslücke wäre.

Uploadscript Tutorial Vorraussetzungen

mittlere PHP [...]]]></description>
			<content:encoded><![CDATA[<p>Da ich mich in letzter Zeit ein bisschen mit diesem Thema befasst habe, habe ich ein kleines Tutorial zum Thema PHP Uploadscript geschrieben. Ziel ist es, Dateien aus dem Browser direkt in ein Verzeichnis zu laden. Auch sollen die hochzuladenden Dateitypen in unserem Uploadscript beschränkbar sein da dies eine gravierende Sicherheitslücke wäre.<br />
<span id="more-26"></span></p>
<h2>Uploadscript Tutorial Vorraussetzungen</h2>
<ul>
<li>mittlere PHP Kenntnisse</li>
<li>Schwierigkeit: Mittel</li>
</ul>
<h2>Uploadscript Sicherheit</h2>
<p>Man stelle sich nun vor es wäre jedem erlaubt jeden beliebigen Dateityp auf den Server zu laden. So wäre es einfach mittels einer hochgeladenen .php Datei einen Angriff auf den Server zu starten. Deshalb sollte vorgegeben werden welche Dateitypen erlaubt sind, und welche nicht.<br />
Ein weiteres Sicherheitsrisiko sind die Servereinstellungen. Leider gibt es im World Wide Web immer noch schwarze Schafe unter den Webhostern, welche einen unprofessionellen und völlig falsch konfigurierten Server bzw. Webspace anbieten. Es ist also möglich das Dateien wie bild.php.jpg als php Datei ausgeführt werden. Dies sollte vor Installation eines Uploadscriptes unbedingt beachtet werden (Bevor du das Tutorial also weiterliest, prüfe bitte ob dies bei dir der Fall ist).</p>
<h2>Das Uploadscript</h2>
<p>Ich werde als erstes wieder das komplette Uploadscript posten, und dies dann im Laufe des Tutorials durcharbeiten.</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #0000ff;">$max_size</span> = <span style="color: #cc66cc;">2</span>; <span style="color: #808080; font-style: italic;">// In MB</span>
<span style="color: #0000ff;">$max_size</span> = <span style="color: #0000ff;">$max_size</span>*<a href="http://www.php.net/pow"><span style="color: #000066;">pow</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$upload_pfad</span> = <span style="color: #ff0000;">&quot;uploads/&quot;</span>;
<span style="color: #0000ff;">$nachricht</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> check_file<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$dateiname</span>, <span style="color: #0000ff;">$pfad</span>, <span style="color: #0000ff;">$error</span>, <span style="color: #0000ff;">$mimetyp</span>, <span style="color: #0000ff;">$max_size</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$error</span> = <span style="color: #000000; font-weight: bold;">false</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/* Fehlermeldungen definieren */</span>
	<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span>;
		<span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Die hochgeladene Datei
			überschreitet die maximal festgelegte Größe.&quot;</span>;
		<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span>;
		<span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Die hochgeladene Datei
			überschreitet die maximal festgelegte Größe.&quot;</span>;
		<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">3</span>;
		<span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Die Datei wurde nur teilweise hochgeladen,
			versuchen sie es erneut&quot;</span>;
		<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">4</span>;
		<span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Es wurde keine Datei hochgeladen.&quot;</span>;
		<span style="color: #b1b100;">break</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/* Nochmals Größe der Datei prüfen */</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/filesize"><span style="color: #000066;">filesize</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;tmp_name&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>&gt;<span style="color: #0000ff;">$max_size</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Die hochgeladene Datei
			überschreitet die maximal festgelegte Größe.&quot;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/* Dateityp prüfen */</span>
	<span style="color: #0000ff;">$mime_erlaubt</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;image/gif&quot;</span>,
				<span style="color: #ff0000;">&quot;image/jpeg&quot;</span>,
				<span style="color: #ff0000;">&quot;image/png&quot;</span>,
				<span style="color: #ff0000;">&quot;text/html&quot;</span>,
				<span style="color: #ff0000;">&quot;text/plain&quot;</span>,
				<span style="color: #ff0000;">&quot;text/css&quot;</span>,
				<span style="color: #ff0000;">&quot;application/zip&quot;</span>,
				<span style="color: #ff0000;">&quot;video/mpeg&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/in_array"><span style="color: #000066;">in_array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$mimetyp</span>, <span style="color: #0000ff;">$mime_erlaubt</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Unerlaubter Dateityp&quot;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/* 	Prüfen ob Datei schon existiert,
		wenn Ja, die datei umbennenen */</span>
	<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/file_exists"><span style="color: #000066;">file_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$pfad</span>.<span style="color: #0000ff;">$dateiname</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$dateiname</span> = <span style="color: #ff0000;">&quot;a_&quot;</span>.<span style="color: #0000ff;">$dateiname</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$dateiname</span>;	
&nbsp;
	<span style="color: #808080; font-style: italic;">/* 	Fehlermeldungen zurückgeben, wenn keine Fehler
		wird false zurückgegeben */</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$error</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Datei hochladen */</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'action'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> and <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'action'</span><span style="color: #66cc66;">&#93;</span>==<span style="color: #ff0000;">&quot;upload&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
<span style="color: #0000ff;">$nachricht</span> = check_file<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #66cc66;">&#93;</span>,
			<span style="color: #0000ff;">$upload_pfad</span>,
			<span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;error&quot;</span><span style="color: #66cc66;">&#93;</span>,
			<span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;type&quot;</span><span style="color: #66cc66;">&#93;</span>,
			<span style="color: #0000ff;">$max_size</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$nachricht</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">/* File nun in das richtige Verzeichnis verschieben */</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/move_uploaded_file"><span style="color: #000066;">move_uploaded_file</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;tmp_name&quot;</span><span style="color: #66cc66;">&#93;</span>,
	<span style="color: #0000ff;">$upload_pfad</span>.<span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/chmod"><span style="color: #000066;">chmod</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$upload_pfad</span>.<span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #cc66cc;">0755</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #0000ff;">$nachricht</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Rechte der Datei wurden nicht gesetzt,
					dies ist möglicherweise eine
					Sicherheitslücke&quot;</span>;
&nbsp;
		<span style="color: #0000ff;">$nachricht</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Datei wurde erfolgreich hochgeladen&quot;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">else</span>
		<span style="color: #0000ff;">$nachricht</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Unbekannter Fehler!
				Bitte versuchen sie es erneut&quot;</span>;	
&nbsp;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">&lt;form</span></a> <span style="color: #000066;">enctype</span>=<span style="color: #ff0000;">&quot;multipart/form-data&quot;</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;?action=upload&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;POST&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">&lt;input</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;MAX_FILE_SIZE&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;&lt;?php echo $max_size ?&gt;</span>&quot;&gt;
Datei hochladen:
<span style="color: #009900;">&lt;input name=&quot;</span>dateiupload<span style="color: #ff0000;">&quot; type=&quot;</span>file<span style="color: #ff0000;">&quot;&gt;</span>
<span style="color: #009900;">&lt;input type=&quot;</span>submit<span style="color: #ff0000;">&quot; value=&quot;</span>Upload<span style="color: #ff0000;">&quot;&gt;</span>
<span style="color: #009900;">&lt;/form&gt;</span>
</span></pre>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
 <span style="color: #808080; font-style: italic;">/* Fehlermeldung ausgeben */</span>
<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$nachricht</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$msg</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$msg</span>.<span style="color: #ff0000;">&quot;&lt;br&gt;&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p>So nun schauen wir uns das ganze etwas näher an, als erstes den HTML Teil.</p>
<pre class="html4strict">&nbsp;
<span style="color: #009900;"><a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">&lt;form</span></a> <span style="color: #000066;">enctype</span>=<span style="color: #ff0000;">&quot;multipart/form-data&quot;</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;?action=upload&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;POST&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">&lt;input</span></a> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;MAX_FILE_SIZE&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;&lt;?php echo $max_size ?&gt;</span>&quot;&gt;
Datei hochladen:
<span style="color: #009900;">&lt;input name=&quot;</span>dateiupload<span style="color: #ff0000;">&quot; type=&quot;</span>file<span style="color: #ff0000;">&quot;&gt;</span>
<span style="color: #009900;">&lt;input type=&quot;</span>submit<span style="color: #ff0000;">&quot; value=&quot;</span>Upload<span style="color: #ff0000;">&quot;&gt;</span>
<span style="color: #009900;">&lt;/form&gt;</span>
</span></pre>
<p>Durch dieses Formular können mit jedem RFC-1867 konformen Browser (dazu gehören der Netscape Navigator 3 oder höher, Microsoft Internet Explorer 3 mit einem Patch von Microsoft oder höher ohne Patch) Dateiuploads durchgeführt werden. Mittels PHP kann man dann steuern wer Dateien hochladen darf und was mit diesen Dateien geschieht. Sobald dieses Formular abgeschickt wurde, wird eine Datei in ein temporäres Verzeichnis geuploaded. Mit MAX_FILE_SIZE kann erstmal einfach eine maximale Dateigröße vorgegeben werden (Welche in diesem Tutorial in der Variable $max_size steht). <strong>Achtung:</strong> Diese Prüfung kann sehr einfach umgangen werden!<br />
Kommen wir zum nächsten Teil des PHP Uploadscript Tutorials, der Funktion check_file() welche den MIME-Typ, die Dateigröße und änhliches prüft. Als ersten Teil der Funktion schauen wir uns die Variable $_SERVER["dateiupload"]["error"] an, in welcher, falls es zu einem Uploadfehler kommt, ein Fehlercode steht. (1, 2, 3 oder 4).</p>
<pre class="php">&nbsp;
	<span style="color: #808080; font-style: italic;">/* Fehlermeldungen definieren */</span>
	<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span>;
		<span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Die hochgeladene Datei
			überschreitet die maximal festgelegte Größe.&quot;</span>;
		<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span>;
		<span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Die hochgeladene Datei
			überschreitet die maximal festgelegte Größe.&quot;</span>;
		<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">3</span>;
		<span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Die Datei wurde nur teilweise hochgeladen,
			versuchen sie es erneut&quot;</span>;
		<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">4</span>;
		<span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Es wurde keine Datei hochgeladen.&quot;</span>;
		<span style="color: #b1b100;">break</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>In diesem Abschnitt des Uploadscriptes wird also mittels Switch Abfrage geprüft welcher Fehler vorkam, und gegebenenfalls eine passende Fehlermeldung in das Array $error, welches am Ende der Funktion zurückgegeben wird, geschrieben.<br />
Im nächsten Teil der Funktion check_file(), das nochmalige prüfen der Dateigröße, da wie oben schon beschrieben die Vorgabe mittels MAX_FILE_SIZE unsicher ist.</p>
<pre class="php">&nbsp;
	<span style="color: #808080; font-style: italic;">/* Nochmals Größe der Datei prüfen */</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/filesize"><span style="color: #000066;">filesize</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;tmp_name&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>&gt;<span style="color: #0000ff;">$max_size</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Die hochgeladene Datei
			überschreitet die maximal festgelegte Größe.&quot;</span>;
&nbsp;</pre>
<p>Es wird also die Dateigröße der bereits hochgeladene Datei (temporär gespeichert) überprüft, und falls diese Größe zu groß ist, wird eine Fehlermeldung in unserer Array $error geschrieben. Im nächsten Teil von check_file() wird der MIME-Typ geprüft, denn es werden nur einige Vorgegebene MIME-Typen in dem Uploadscript zugelassen.</p>
<pre class="php">&nbsp;
	<span style="color: #808080; font-style: italic;">/* Dateityp prüfen */</span>
	<span style="color: #0000ff;">$mime_erlaubt</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;image/gif&quot;</span>,
				<span style="color: #ff0000;">&quot;image/jpeg&quot;</span>,
				<span style="color: #ff0000;">&quot;image/png&quot;</span>,
				<span style="color: #ff0000;">&quot;text/html&quot;</span>,
				<span style="color: #ff0000;">&quot;text/plain&quot;</span>,
				<span style="color: #ff0000;">&quot;text/css&quot;</span>,
				<span style="color: #ff0000;">&quot;application/zip&quot;</span>,
				<span style="color: #ff0000;">&quot;video/mpeg&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/in_array"><span style="color: #000066;">in_array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$mimetyp</span>, <span style="color: #0000ff;">$mime_erlaubt</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #0000ff;">$error</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Unerlaubter Dateityp&quot;</span>;
&nbsp;</pre>
<p>Hier erstellen wir einen Array mit dem Namen $mime_erlaubt, in welchen alle erlaubten MIME Typen stehen. Mittels einer If Abfrage und der Funktion in_array prüfen wir nun ob der MIME Typ der hochgeladenen Datei ein erlaubter MIME Typ ist. (Den MIME Typ der hochgeladenen Datei bekommt man mittels $_FILES["dateiupload"]["type"]).<br />
Im vorletzten Abschnitt unserer eigenen Funktion check_file() überprüfen wir ob eine Datei schon existiert, und geben der Datei gegebenenfalls einen Präfix...</p>
<pre class="php">&nbsp;
	<span style="color: #808080; font-style: italic;">/* 	Prüfen ob Datei schon existiert,
		wenn Ja, die datei umbennenen */</span>
	<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/file_exists"><span style="color: #000066;">file_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$pfad</span>.<span style="color: #0000ff;">$dateiname</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$dateiname</span> = <span style="color: #ff0000;">&quot;a_&quot;</span>.<span style="color: #0000ff;">$dateiname</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$dateiname</span>;
&nbsp;</pre>
<p>Es wird also mittels While-Schleife und der Funktion file_exists geprüft ob die Datei mit dem Dateinamen $dateinamen im Verzeichnis $pfad vorhanden ist, und solange dies der Fall ist wird dem Dateinamen ein "a_" angehängt. Abschließend wird unserer Superglobalen $_FILES["dateiupload"]["name"] welchen den Namen der Datei beinhaltet, der neue Dateiname zugewiesen.<br />
Als Abschluss der Funktion check_file() geben wir jetzt nur noch den Array mit den Fehlermeldungen zurück.<br />
Kommen wir also zum nächsten Schritt des Tutorials, dem aufrufen der Funktion und dem Verschieben der temporär gespeicherten Datei. </p>
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">/* Rufen wir also die selbt definierte Funktion auf
Und übergeben den Dateinamen, den Pfad,
ggf den Fehler der beim Hochladen verursacht wurde
Den MIME-Typ und die maximale Filegröße */</span>
<span style="color: #0000ff;">$nachricht</span> = check_file<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #66cc66;">&#93;</span>,
			<span style="color: #0000ff;">$upload_pfad</span>,
			<span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;error&quot;</span><span style="color: #66cc66;">&#93;</span>,
			<span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;type&quot;</span><span style="color: #66cc66;">&#93;</span>,
			<span style="color: #0000ff;">$max_size</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">/* Da wir die Fehlermeldungen in der Funktion zurückgeben
enthält nun die Variable $nachricht Fehlermeldungen, wenn
welche vorhanden sein sollten. Deshalb prüfen wir im
nächsten Schritt ob diese Variable false, d.h nicht gesetzt
ist */</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$nachricht</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Mittels move_uploaded_file verschieben wir die temporär
gespeicherte Datei in unser Wunschverzeichnis */</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/move_uploaded_file"><span style="color: #000066;">move_uploaded_file</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;tmp_name&quot;</span><span style="color: #66cc66;">&#93;</span>,
	<span style="color: #0000ff;">$upload_pfad</span>.<span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/* Und als Abschluss noch chmod Rechte setzen damit
		nicht jeder mit den Dateien machen kann was er will */</span>
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/chmod"><span style="color: #000066;">chmod</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$upload_pfad</span>.<span style="color: #0000ff;">$_FILES</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;dateiupload&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #66cc66;">&#93;</span>, <span style="color: #cc66cc;">0755</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #0000ff;">$nachricht</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Rechte der Datei wurden nicht gesetzt,
					dies ist möglicherweise eine
					Sicherheitslücke&quot;</span>;
&nbsp;
		<span style="color: #0000ff;">$nachricht</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Datei wurde erfolgreich hochgeladen&quot;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">else</span>
		<span style="color: #0000ff;">$nachricht</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #ff0000;">&quot;Unbekannter Fehler!
				Bitte versuchen sie es erneut&quot;</span>;	
&nbsp;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>Und um das Tutorial noch abzuschließen werden die Meldungen aus dem Array $nachricht noch mittels einer Foreach-Schleife ausgegeben. </p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
 <span style="color: #808080; font-style: italic;">/* Fehlermeldung ausgeben */</span>
<span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$nachricht</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$msg</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$msg</span>.<span style="color: #ff0000;">&quot;&lt;br&gt;&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p>Ich hoffe ich konnte euch mit diesem PHP Uploadscript Tutorial etwas helfen und wäre über Rückmeldungen, Fragen oder Kommentare jeder Art dankbar.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.homepage-hilfe.org/php-uploadscript-tutorial/feed</wfw:commentRss>
		</item>
		<item>
		<title>Dateidownload mittels PHP erzwingen</title>
		<link>http://www.homepage-hilfe.org/dateidownload-php-erzwingen</link>
		<comments>http://www.homepage-hilfe.org/dateidownload-php-erzwingen#comments</comments>
		<pubDate>Fri, 06 Jun 2008 07:41:23 +0000</pubDate>
		<dc:creator>Leichti</dc:creator>
		
		<category><![CDATA[PHP Tipps und Tricks]]></category>

		<category><![CDATA[dateidownload]]></category>

		<category><![CDATA[erzwungen]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.homepage-hilfe.org/?p=24</guid>
		<description><![CDATA[Mittels PHP ist es möglich Dateien von einem Server auszugeben und einen Download zu erzwingen. Dies ist praktisch wenn man Dateien zum Download anbieten möchte welche im Normalfall ausgegeben werden würden. Ich habe ein kleines Script geschrieben, welches eigentlich selbst erklärend sein sollte

Script um Dateidownload zu erzwingen
&#160;
function download_file&#40;$file&#41; &#123;
	$filename = basename&#40;$file&#41;;
	$filesize = filesize&#40;$file&#41;;
	header&#40;&#34;Content-Type: application/force-download&#34;&#41;;
	header&#40;&#34;Content-Disposition: attachment; [...]]]></description>
			<content:encoded><![CDATA[<p>Mittels PHP ist es möglich Dateien von einem Server auszugeben und einen Download zu erzwingen. Dies ist praktisch wenn man Dateien zum Download anbieten möchte welche im Normalfall ausgegeben werden würden. Ich habe ein kleines Script geschrieben, welches eigentlich selbst erklärend sein sollte<br />
<span id="more-24"></span></p>
<h2>Script um Dateidownload zu erzwingen</h2>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> download_file<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0000ff;">$filename</span> = <a href="http://www.php.net/basename"><span style="color: #000066;">basename</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0000ff;">$filesize</span> = <a href="http://www.php.net/filesize"><span style="color: #000066;">filesize</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span><span style="color: #66cc66;">&#41;</span>;
	<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-Type: application/force-download&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-Disposition: attachment; filename=&quot;</span>.<span style="color: #0000ff;">$filename</span><span style="color: #66cc66;">&#41;</span>;
	<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-Length: $filesize&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<a href="http://www.php.net/readfile"><span style="color: #000066;">readfile</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
download_file<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;pfad/datei.php&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<h2>Erklärung des Downloadscriptes</h2>
<p>In unserer Funktion lesen wirmittels basename("file") den Dateinamen aus und speichern diesen in die Variable $filename. Mittels filesize("file") wird die Dateigröße ermittelt, und in die Variable $filesize gespeichert. Jetzt setzten wir einige Headerinformationen, damit der Browser weiß dass es sich um einen Dateidownload handelt. Nun geben wir Datei noch mittels readfile("file") aus. Und das war es schon! Diese Funktion kann jetzt einfach mittels download_file("file") aufgerufen werden! Viel spaß mit eurem erzwungenem Dateidownload</p>
]]></content:encoded>
			<wfw:commentRss>http://www.homepage-hilfe.org/dateidownload-php-erzwingen/feed</wfw:commentRss>
		</item>
		<item>
		<title>Einfaches PHP Thumbnail Tutorial</title>
		<link>http://www.homepage-hilfe.org/einfaches-php-thumbnail-tutorial</link>
		<comments>http://www.homepage-hilfe.org/einfaches-php-thumbnail-tutorial#comments</comments>
		<pubDate>Thu, 05 Jun 2008 18:53:27 +0000</pubDate>
		<dc:creator>Leichti</dc:creator>
		
		<category><![CDATA[PHP Tipps und Tricks]]></category>

		<category><![CDATA[automatisch]]></category>

		<category><![CDATA[GDlib]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[Thumbnail]]></category>

		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.homepage-hilfe.org/?p=23</guid>
		<description><![CDATA[Thumbnails sind automatisch erzeugte, meist verkleinerte Versionen, eines originalen Bildes. Thumnails können praktisch als Vorschaubilder genutzt werden, da die Dateigröße von Thumbnails kleiner ist als die Größe der Originaldatei. Ich möchte hier ein kleines Tutorial zur Thumnailerstellung bereitstellen, bzw ein Skript zum Download anbieten.

Thumbnail Tutorialvorraussetzungen

PHP Kenntnisse
GD Library

Das Thumnial Tutorial insgesamt hat einen mittleren Schwierigkeitsgrad. 
Zuerst [...]]]></description>
			<content:encoded><![CDATA[<p>Thumbnails sind automatisch erzeugte, meist verkleinerte Versionen, eines originalen Bildes. Thumnails können praktisch als Vorschaubilder genutzt werden, da die Dateigröße von Thumbnails kleiner ist als die Größe der Originaldatei. Ich möchte hier ein kleines Tutorial zur Thumnailerstellung bereitstellen, bzw ein Skript zum Download anbieten.<br />
<span id="more-23"></span></p>
<h2>Thumbnail Tutorialvorraussetzungen</h2>
<ul>
<li>PHP Kenntnisse</li>
<li>GD Library</li>
</ul>
<p>Das Thumnial Tutorial insgesamt hat einen mittleren Schwierigkeitsgrad. </p>
<p>Zuerst werde ich einfach das ganze Scipt zeigen, und dieses zerlegen wir langsam im Laufe des Tutorials.</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> new_thumb<span style="color: #66cc66;">&#40;</span>	<span style="color: #0000ff;">$picturepath</span>,
					<span style="color: #0000ff;">$thumbpath</span> = <span style="color: #000000; font-weight: bold;">false</span>,
					<span style="color: #0000ff;">$newsize</span> = <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/* Prüfen ob Datei existiert */</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/file_exists"><span style="color: #000066;">file_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$picturepath</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Grafik nicht vorhanden&quot;</span>;
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/* MIME-Typ auslesen */</span>
	<span style="color: #0000ff;">$size</span>=<a href="http://www.php.net/getimagesize"><span style="color: #000066;">getimagesize</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$picturepath</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;1&quot;</span>;
		<span style="color: #0000ff;">$oldpic</span> = imagecreatefromgif<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$picturepath</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;2&quot;</span>;
		<span style="color: #0000ff;">$oldpic</span> = imagecreatefromjpeg<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$picturepath</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;3&quot;</span>;
		<span style="color: #0000ff;">$oldpic</span> = imagecreatefrompng<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$picturepath</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #000000; font-weight: bold;">default</span>;
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Grafiktyp wird nicht unterstützt&quot;</span>;
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/* Alte Maße auslesen */</span>
	<span style="color: #0000ff;">$width</span> = <span style="color: #0000ff;">$size</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
	<span style="color: #0000ff;">$height</span> = <span style="color: #0000ff;">$size</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>; 
&nbsp;
	<span style="color: #808080; font-style: italic;">/* Neue Maße errechnen */</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$width</span>&gt;=<span style="color: #0000ff;">$height</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$newwidth</span> = <span style="color: #0000ff;">$newsize</span>;
		<span style="color: #0000ff;">$newheight</span> = <span style="color: #0000ff;">$newsize</span>*<span style="color: #0000ff;">$height</span>/<span style="color: #0000ff;">$width</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$newheight</span> = <span style="color: #0000ff;">$newsize</span>;
		<span style="color: #0000ff;">$newwidth</span> = <span style="color: #0000ff;">$newsize</span>*<span style="color: #0000ff;">$width</span>/<span style="color: #0000ff;">$height</span>;
	<span style="color: #66cc66;">&#125;</span>	
&nbsp;
	<span style="color: #808080; font-style: italic;">/* Neues Bild erstellen mit den neuen Maßen */</span>
	<span style="color: #0000ff;">$newpic</span>=imagecreatetruecolor<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newwidth</span>,<span style="color: #0000ff;">$newheight</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/* Jetzt wird das Bild nur noch verkleinerd */</span>
	imagecopyresized<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span>,<span style="color: #0000ff;">$oldpic</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,
				<span style="color: #0000ff;">$newwidth</span>,<span style="color: #0000ff;">$newheight</span>,<span style="color: #0000ff;">$width</span>,<span style="color: #0000ff;">$height</span><span style="color: #66cc66;">&#41;</span>; 
&nbsp;
	<span style="color: #808080; font-style: italic;">/* Und hier schon ausgegeben wenn es nicht gespeichert wird */</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$thumbpath</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">/* Grafik ausgeben */</span>
		<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;1&quot;</span>;	<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-type: image/gif&quot;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">return</span> imagegif<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;2&quot;</span>;	<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-type: image/jpg&quot;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">return</span> imagejpeg<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;3&quot;</span>;	<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-type: image/png&quot;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">return</span> imagepng<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/* Wenn es gespeichert werden soll */</span>
	<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;1&quot;</span>;	<span style="color: #b1b100;">return</span> imagegif<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span>, <span style="color: #0000ff;">$thumbpath</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;2&quot;</span>;	<span style="color: #b1b100;">return</span> imagejpeg<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span>, <span style="color: #0000ff;">$thumbpath</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;3&quot;</span>;	<span style="color: #b1b100;">return</span> imagepng<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span>, <span style="color: #0000ff;">$thumbpath</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">//Bilderspeicher freigeben</span>
    imagedestroy<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$oldpic</span><span style="color: #66cc66;">&#41;</span>;
    imagedestroy<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">/* Jetzt geben wir ein Bild aus */</span>
new_thumb<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;bild1.jpg&quot;</span>, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #cc66cc;">500</span><span style="color: #66cc66;">&#41;</span>
&nbsp;</pre>
<p>Das Bild bild1.jpg wird jetzt dynamisch erstellt (Thumbnail) und im Browser ausgegeben. Eine Besonderheit ist, das die maximale Seitenlänge in unserem Beispiel 500 Beträgt, entweder bei der Höhe oder bei der Breite (je nachdem was Größer ist). Wollen wir jetzt aber kein Thumbnail ausgeben sondern eines speichern, so müssen wir die Funktion einfach anders aufrufen.</p>
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">/* Jetzt speichern wir ein Bild */</span>
new_thumb<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;bild1.jpg&quot;</span>, <span style="color: #ff0000;">&quot;bild1_thumb.jpg&quot;</span>, <span style="color: #cc66cc;">500</span><span style="color: #66cc66;">&#41;</span>
&nbsp;</pre>
<p>Nun wird unser Bild1 als Thumbnail gespeichert, mit der gleichen maximalen Seitenlänge wie oben (500px).</p>
<h2>Was passiert eigentlich in unserer Funktion?</h2>
<p>Schauen wir uns also den ersten Teil der Funktion an, wir überprüfen ob die Grafik, aus welcher wir ein Thumbnail erstellen wollen vorhanden ist. Dies geschieht mit file_exists()</p>
<pre class="php">&nbsp;
	<span style="color: #808080; font-style: italic;">/* Prüfen ob Datei existiert */</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/file_exists"><span style="color: #000066;">file_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$picturepath</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Grafik nicht vorhanden&quot;</span>;
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>Kommen wir zum nächsten Punkt, zum "Erstellen" eines Bildes aus der Originalgrafik (Originaldatei)</p>
<pre class="php">&nbsp;
	<span style="color: #808080; font-style: italic;">/* MIME-Typ auslesen */</span>
	<span style="color: #0000ff;">$size</span>=<a href="http://www.php.net/getimagesize"><span style="color: #000066;">getimagesize</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$picturepath</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;1&quot;</span>;
		<span style="color: #0000ff;">$oldpic</span> = imagecreatefromgif<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$picturepath</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;2&quot;</span>;
		<span style="color: #0000ff;">$oldpic</span> = imagecreatefromjpeg<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$picturepath</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;3&quot;</span>;
		<span style="color: #0000ff;">$oldpic</span> = imagecreatefrompng<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$picturepath</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
&nbsp;
		<span style="color: #000000; font-weight: bold;">default</span>;
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Grafiktyp wird nicht unterstützt&quot;</span>;
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>Mittels getimagesize(pfad) lesen wir diverse Informationen einer Grafikdatei aus und speichern diese als Array in $size ($size[0] enthält die Breite, $size[1] enthält die Höhe, $size[2] enthält einen Integerwert welcher einem MIME-Typ zugewiesen wird).<br />
Also erstellen wir entweder eine gif, jpeg oder png Grafik (Thumbnails von anderen Grafiken zu erstellen ist mit diesem Script leider <strong>nicht</strong> möglich!). Im nächsten Teil der Funktion (Tutorials) lesen wir die Breite und Höhe des Originalbildes aus und berechnen gleich die Maße unseres Thumbnails</p>
<pre class="php">&nbsp;
	<span style="color: #808080; font-style: italic;">/* Alte Maße auslesen */</span>
	<span style="color: #0000ff;">$width</span> = <span style="color: #0000ff;">$size</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
	<span style="color: #0000ff;">$height</span> = <span style="color: #0000ff;">$size</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>; 
&nbsp;
	<span style="color: #808080; font-style: italic;">/* Neue Maße errechnen */</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$width</span>&gt;=<span style="color: #0000ff;">$height</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$newwidth</span> = <span style="color: #0000ff;">$newsize</span>;
		<span style="color: #0000ff;">$newheight</span> = <span style="color: #0000ff;">$newsize</span>*<span style="color: #0000ff;">$height</span>/<span style="color: #0000ff;">$width</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$newheight</span> = <span style="color: #0000ff;">$newsize</span>;
		<span style="color: #0000ff;">$newwidth</span> = <span style="color: #0000ff;">$newsize</span>*<span style="color: #0000ff;">$width</span>/<span style="color: #0000ff;">$height</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>Wie Oben schon beschrieben holen wir uns aus dem Array $size die Breite und die Höhe, danach prüfen wir ob unser Bild ein Bild im Querformat (Breite>Höhe) oder Hochformat (Höhe>Breite) ist. Dies geschieht mit einer einfachen If-Abfrage.<br />
<strong>Beispiel:</strong> Nehmen wir an unsere Ausgangsgrafik hat die Maße 1000px Breite und 500px Höhe (Querformat denn die Breite > Höhe). Wollen wir jetzt eine <strong>maximale Seitenlänge</strong> von 200px haben, so wird jetzt der Variable $newwidth der Wert 200 zugewiesen. Die Variable $newheight wird berechnet (200*500/1000) und wir bekommen eine neue Höhe von 100px für das <strong>Thumbnail</strong> heraus. Somit bleiben die Seitenverhältnisse des Bildes auch im Thumnail erhalten und es wird nicht verzerrt. </p>
<p>Kommen wir nun zum nächsten Teil der Funktion (des Tutorials)</p>
<pre class="php">&nbsp;
	<span style="color: #808080; font-style: italic;">/* Neues Bild erstellen mit den neuen Maßen */</span>
	<span style="color: #0000ff;">$newpic</span>=imagecreatetruecolor<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newwidth</span>,<span style="color: #0000ff;">$newheight</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">/* Jetzt wird das Bild nur noch verkleinerd */</span>
	imagecopyresized<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span>,<span style="color: #0000ff;">$oldpic</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,
				<span style="color: #0000ff;">$newwidth</span>,<span style="color: #0000ff;">$newheight</span>,<span style="color: #0000ff;">$width</span>,<span style="color: #0000ff;">$height</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Als erstes wird mit imagecreatetruecolor() ein neues leeres Bild erstellt, und in dieses werden dann die Farbwerte vom der Originalgrafik mittels imagecopyresized() eingefügt. Nun nähern wir uns schon dem Ende des Tutorials an, nämlich der Ausgabe bzw Speicherung unseres Thumbnails.</p>
<pre class="php">&nbsp;
	<span style="color: #808080; font-style: italic;">/* Und hier schon ausgegeben wenn es nicht gespeichert wird */</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$thumbpath</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">/* Grafik ausgeben */</span>
		<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;1&quot;</span>;	<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-type: image/gif&quot;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">return</span> imagegif<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;2&quot;</span>;	<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-type: image/jpg&quot;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">return</span> imagejpeg<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;3&quot;</span>;	<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-type: image/png&quot;</span><span style="color: #66cc66;">&#41;</span>;
					<span style="color: #b1b100;">return</span> imagepng<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>Wenn das Thumbnail nicht gespeichert sondern ausgegeben werden soll, muss beim Aufrufen unserer selbstgeschriebenen Funktion new_thumb() als Speicherort ($thumbpath) false (= der Standartwert) angegeben sein. Mit der Switch prüfen wir wieder den MIME-Typ und geben die Datei aus. Wollen wir das Thumbnail allerdings nicht ausgeben sondern speichern, muss die Variable $thumbpath gesetzt sein. Dann läuft das Script weiter und wir kommen zum Ende der Funktion:</p>
<pre class="php">&nbsp;
	<span style="color: #808080; font-style: italic;">/* Wenn es gespeichert werden soll */</span>
	<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">switch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;1&quot;</span>;	<span style="color: #b1b100;">return</span> imagegif<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span>, <span style="color: #0000ff;">$thumbpath</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;2&quot;</span>;	<span style="color: #b1b100;">return</span> imagejpeg<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span>, <span style="color: #0000ff;">$thumbpath</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
		<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">&quot;3&quot;</span>;	<span style="color: #b1b100;">return</span> imagepng<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span>, <span style="color: #0000ff;">$thumbpath</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #b1b100;">break</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>Wieder mittels Switch-Abfrage den MIME-Typ abfragen und dann wird das Bild mittels imagejpeg, imagegif oder imagepng gespeichert, da ein Speicherort ($thumbpath) angegeben wurde. Zum abschluss leeren wir nur noch den Speicher:</p>
<pre class="php">&nbsp;
<span style="color: #808080; font-style: italic;">//Bilderspeicher freigeben</span>
    imagedestroy<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$oldpic</span><span style="color: #66cc66;">&#41;</span>;
    imagedestroy<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$newpic</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Ich hoffe ich konnte mit diesem Tutorial einigen Leuten helfen ihre eignenen Thumnails zu erstllen und wäre für Rückmeldungen (mittels der Kommentarfunktion) dankbar.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.homepage-hilfe.org/einfaches-php-thumbnail-tutorial/feed</wfw:commentRss>
		</item>
		<item>
		<title>Firefox Addons für Webentwickler</title>
		<link>http://www.homepage-hilfe.org/firefox-addons-fuer-webentwickler</link>
		<comments>http://www.homepage-hilfe.org/firefox-addons-fuer-webentwickler#comments</comments>
		<pubDate>Tue, 03 Jun 2008 21:14:23 +0000</pubDate>
		<dc:creator>Leichti</dc:creator>
		
		<category><![CDATA[Sonstiges]]></category>

		<category><![CDATA[Addons]]></category>

		<category><![CDATA[Entwickler]]></category>

		<category><![CDATA[Entwicklung]]></category>

		<category><![CDATA[Firefox]]></category>

		<category><![CDATA[Webentwickler]]></category>

		<category><![CDATA[Webentwicklung]]></category>

		<guid isPermaLink="false">http://www.homepage-hilfe.org/?p=22</guid>
		<description><![CDATA[Einige Webdesigner oder Webentwickler benutzen beim Entwickeln ihrer Webseite immer noch den Internet Explorer. Doch es ist sinnvoller sich für den Open Source Konkurenten zu entscheiden, den inzwischen haben sich einige, sehr wichtige Firefox Addons für die Webentwicklung bei mir angesammelt, die für die Webentwicklung nicht mehr wegzudenken sind. Diese Firefox Addons nehmen einem sehr [...]]]></description>
			<content:encoded><![CDATA[<p>Einige Webdesigner oder Webentwickler benutzen beim Entwickeln ihrer Webseite immer noch den Internet Explorer. Doch es ist sinnvoller sich für den Open Source Konkurenten zu entscheiden, den inzwischen haben sich einige, sehr wichtige <strong>Firefox Addons</strong> für die Webentwicklung bei mir angesammelt, die für die Webentwicklung nicht mehr wegzudenken sind. Diese <strong>Firefox Addons</strong> nehmen einem sehr viel Zeit bei der Webseitenerstellung (Webentwicklung ab). Hier möchte ich euch die vier (4) bei mir installierten Firefox Addons vorstellen, welche einem das Entwickeln von Webseiten sehr erleichtern.<br />
<span id="more-22"></span></p>
<h2><a href="http://www.erweiterungen.de/detail/Web_Developer/">Web Developer, das beste Firefox Addon für die Webentwicklung</a></h2>
<p>Web Developer ist meiner Meinung nach eines der besten und wichtigsten Firefox Addons für die Entwicklung von Webseiten, es mittlerweile sogar in deutscher Sprache verfügbar. Mit den Web Developer kann alles Erdenkliche deaktiviert/aktiviert/verändert werden. </p>
<h2><a href="https://addons.mozilla.org/de/firefox/addon/1843">Firebug</a></h2>
<p>Ist man die Funktionalität von Firebug einmal gewöhnt, so ist dieses Addon kaum noch weg zu denken. Für mich gehört Firebug zur Standartausrüstung eines Webentwicklers. Es Hilft bei der Fehlersuche im HTML-Code bzw auch im Javascript-Code. Die Visualisierung von div-Containern macht das Tool zu einer Super Hilfe.</p>
<h2><a href="http://www.erweiterungen.de/detail/ColorZilla/">ColorZilla</a></h2>
<p>Man surft durch das Internet und sieht eine schöne Farbe, will jedoch nicht lange im Quelltext (CSS) den RBG-Farbcode bzw. den Hex-Farbcode suchen. Früher startete man Photoshop, nun gehts mit ColorZilla. ColorZilla ist praktisch, zum Beispiel auch um Farben in einem fertigen Template (z.B: für CMS, Foren, Gästebücher etc.) anzupassen. Einfach auf die Farbe im Browser klicken, Farbcode (RBG oder Hex) kopieren und fertig.</p>
<h2><a href="http://www.erweiterungen.de/detail/Google_PageRank_Status/">Google Pagerank Status</a></h2>
<p>Vl mag der Eine oder Andere jetzt sagen: “Was interessiert mich der Pagerank noch?”, aber es ist trotzdem interessant zu schauen, wie der Pagerank der jeweiligen Seite ist. Dieses Addon lässt rechts unten einen kleinen Balken erscheinen welcher den Pagerank anzeigt.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.homepage-hilfe.org/firefox-addons-fuer-webentwickler/feed</wfw:commentRss>
		</item>
		<item>
		<title>Mit PHP Dateigröße beliebiger Dateien auslesen</title>
		<link>http://www.homepage-hilfe.org/mit-php-dateigrose-beliebiger-dateien-auslesen</link>
		<comments>http://www.homepage-hilfe.org/mit-php-dateigrose-beliebiger-dateien-auslesen#comments</comments>
		<pubDate>Mon, 02 Jun 2008 15:27:48 +0000</pubDate>
		<dc:creator>Leichti</dc:creator>
		
		<category><![CDATA[PHP Tipps und Tricks]]></category>

		<category><![CDATA[auslesen]]></category>

		<category><![CDATA[datei]]></category>

		<category><![CDATA[dateigröße]]></category>

		<category><![CDATA[dynamisch]]></category>

		<category><![CDATA[größe]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.homepage-hilfe.org/?p=20</guid>
		<description><![CDATA[Oft möchte man Dateien zum Download anbieten und daneben noch die Dateigröße der Datei anzeigen. Diese Dateigrößen per Hand einzutragen ist eine Menge an Arbeit welche man sich auch sparen kann. Mit PHP ist es sehr einfach möglich die Größen von Dateien zu ermitteln und auszugeben.

Mit der Funktion filesize() kann man die größe einer Datei [...]]]></description>
			<content:encoded><![CDATA[<p>Oft möchte man Dateien zum Download anbieten und daneben noch die Dateigröße der Datei anzeigen. Diese Dateigrößen per Hand einzutragen ist eine Menge an Arbeit welche man sich auch sparen kann. Mit PHP ist es sehr einfach möglich die Größen von Dateien zu ermitteln und auszugeben.<br />
<span id="more-20"></span></p>
<p>Mit der Funktion filesize() kann man die größe einer Datei auslesen. Filzesize() gibt die Größe einer Datei in Bytes zurück, man muss (oder sollte zumindest) diese immer in die entsprechende Einheit umwandeln (kb, mb, gb). Wir schreiben uns also eine kleine Funktion welche das alles für uns übernimmt. </p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> fs_convert <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$datei</span>, <span style="color: #0000ff;">$nachkommastellen</span> = <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/file_exists"><span style="color: #000066;">file_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$datei</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// Wenn Datei nicht existiert</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;0 Byte&quot;</span>;
		<span style="color: #b1b100;">return</span>; <span style="color: #808080; font-style: italic;">// Ende der Funktion</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">$size</span> = <a href="http://www.php.net/filesize"><span style="color: #000066;">filesize</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$datei</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Größe in Bytes</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span> &gt;= <span style="color: #cc66cc;">1073741824</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #808080; font-style: italic;">// Wenn über 1 GB</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/round"><span style="color: #000066;">round</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span>/<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1073741824</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$nachkommastellen</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot; GB&quot;</span>;
&nbsp;
	<span style="color: #b1b100;">elseif</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span> &gt;= <span style="color: #cc66cc;">1048576</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// Wenn über 1 MB</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/round"><span style="color: #000066;">round</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span>/<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1048576</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$nachkommastellen</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot; MB&quot;</span>;
&nbsp;
	<span style="color: #b1b100;">elseif</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span> &gt;= <span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// Wenn über 1 KB</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/round"><span style="color: #000066;">round</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span>/<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$nachkommastellen</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot; KB&quot;</span>;
&nbsp;
	<span style="color: #b1b100;">else</span> <span style="color: #808080; font-style: italic;">// Ansonsten sind es nur Bytes</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a>  <span style="color: #0000ff;">$size</span>.<span style="color: #ff0000;">&quot; Byte&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p>Diese Funktion können wir nun einfach aufrufen und die Dateigröße wird mittels PHP mit der entsprechenden Einheit ausgelesen bzw. zurückgeliefert. Ein kleines Beispiel wie das Ganze aussehen könnte.</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> fs_convert <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$datei</span>, <span style="color: #0000ff;">$nachkommastellen</span> = <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/file_exists"><span style="color: #000066;">file_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$datei</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// Wenn Datei nicht existiert</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;0 Byte&quot;</span>;
		<span style="color: #b1b100;">return</span>; <span style="color: #808080; font-style: italic;">// Ende der Funktion</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">$size</span> = <a href="http://www.php.net/filesize"><span style="color: #000066;">filesize</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$datei</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Größe in Bytes</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span> &gt;= <span style="color: #cc66cc;">1073741824</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #808080; font-style: italic;">// Wenn über 1 GB</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/round"><span style="color: #000066;">round</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span>/<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1073741824</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$nachkommastellen</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot; GB&quot;</span>;
&nbsp;
	<span style="color: #b1b100;">elseif</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span> &gt;= <span style="color: #cc66cc;">1048576</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// Wenn über 1 MB</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/round"><span style="color: #000066;">round</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span>/<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1048576</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$nachkommastellen</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot; MB&quot;</span>;
&nbsp;
	<span style="color: #b1b100;">elseif</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span> &gt;= <span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// Wenn über 1 KB</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/round"><span style="color: #000066;">round</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$size</span>/<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$nachkommastellen</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #ff0000;">&quot; KB&quot;</span>;
&nbsp;
	<span style="color: #b1b100;">else</span> <span style="color: #808080; font-style: italic;">// Ansonsten sind es nur Bytes</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a>  <span style="color: #0000ff;">$size</span>.<span style="color: #ff0000;">&quot; Byte&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<a href="http://www.php.net/die"><span style="color: #000066;">Die</span></a> Datei: &lt;a href=<span style="color: #ff0000;">&quot;email.zip&quot;</span>&gt;email.php&lt;/a&gt; ist
<span style="color: #000000; font-weight: bold;">&lt;?php</span> fs_convert<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;email.zip&quot;</span>, <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span> groß.
&nbsp;
&lt;br&gt;
&lt;br&gt;
&nbsp;
<a href="http://www.php.net/die"><span style="color: #000066;">Die</span></a> Datei: &lt;a href=<span style="color: #ff0000;">&quot;test/datei_2.zip&quot;</span>&gt;Datei <span style="color: #cc66cc;">2</span>&lt;/a&gt; ist
<span style="color: #000000; font-weight: bold;">&lt;?php</span> fs_convert<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;test/datei_2.zip&quot;</span>, <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
groß.
&nbsp;</pre>
<p>In diesem Beispiel müsste die Datei email.zip im selben Verzeichniss liegen, in dem diese Funktion aufgerufen wird. Die Datei datei_2.zip müssten in einem Unterordner namens "test" liegen.<br />
Nun wünsche ich viel Spaß beim dynamischen ermitteln von Dateigrößen mittels PHP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.homepage-hilfe.org/mit-php-dateigrose-beliebiger-dateien-auslesen/feed</wfw:commentRss>
		</item>
		<item>
		<title>PHP Email Adresse auf Gültigkeit überprüfen</title>
		<link>http://www.homepage-hilfe.org/php-email-adresse-auf-gultigkeit-uberprufen</link>
		<comments>http://www.homepage-hilfe.org/php-email-adresse-auf-gultigkeit-uberprufen#comments</comments>
		<pubDate>Fri, 30 May 2008 13:34:21 +0000</pubDate>
		<dc:creator>Leichti</dc:creator>
		
		<category><![CDATA[PHP Tipps und Tricks]]></category>

		<category><![CDATA[Adresse überprüfen]]></category>

		<category><![CDATA[Email]]></category>

		<category><![CDATA[Gültigkeit]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.homepage-hilfe.org/?p=19</guid>
		<description><![CDATA[In Eingabefeldern für Emailadressen ist es nötig die Email Adresse auf Gültigkeit zu überprüfen. Dies ist ganz einfach mit Hilfe von Regulären Ausdrücken (Wenn dir RegEx nichts sagt). Dieses Tutorial soll euch helfen eine Email Adresse mittels PHP auf Gültigkeit überprüfen zu können.

Funktion schreiben um Email Adresse zu Überprüfen
Zuerst einmal zeige ich euch einfach den [...]]]></description>
			<content:encoded><![CDATA[<p>In Eingabefeldern für Emailadressen ist es nötig die Email Adresse auf Gültigkeit zu überprüfen. Dies ist ganz einfach mit Hilfe von Regulären Ausdrücken (<a href="http://tut.php-quake.net/regex.html">Wenn dir RegEx nichts sagt</a>). Dieses Tutorial soll euch helfen eine Email Adresse mittels PHP auf Gültigkeit überprüfen zu können.<br />
<span id="more-19"></span></p>
<h2>Funktion schreiben um Email Adresse zu Überprüfen</h2>
<p>Zuerst einmal zeige ich euch einfach den Code für die Funktion welche überprüft ob die Variable eine gültige Email Adresse ist. </p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> mail_pruefen<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$adresse</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/empty"><span style="color: #000066;">empty</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$adresse</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// Wenn leer</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>; <span style="color: #808080; font-style: italic;">// Funktion beenden</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/* Überprüfen */</span>
	<span style="color: #0000ff;">$regex</span> = <span style="color: #ff0000;">'§[<span style="color: #000099; font-weight: bold;">\w</span>-.]{1,}@[<span style="color: #000099; font-weight: bold;">\w</span>-]{3,}<span style="color: #000099; font-weight: bold;">\.</span>[<span style="color: #000099; font-weight: bold;">\w</span>-]{2,3}§'</span>;
	<a href="http://www.php.net/preg_match"><span style="color: #000066;">preg_match</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$regex</span>, <span style="color: #0000ff;">$adresse</span>, <span style="color: #0000ff;">$matches</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/empty"><span style="color: #000066;">empty</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$matches</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// Wenn keine Email</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>; <span style="color: #808080; font-style: italic;">// Funktion beenden</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/strlen"><span style="color: #000066;">strlen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$matches</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>!=<a href="http://www.php.net/strlen"><span style="color: #000066;">strlen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$adresse</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>; <span style="color: #808080; font-style: italic;">// Funktion beenden</span>
&nbsp;
	<span style="color: #b1b100;">return</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$matches</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #0000ff;">$mailcheck</span> = mail_pruefen<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_POST</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;email&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>So, was passiert hier nun? Die Variable $regex enthält unseren Regulären Ausdruck und überprüft mit Hilfe von preg_match() ob die Variable $adresse eine gültige Email Adresse enthält. $matches ist ist ein Array in das die gültige Email Adresse dann gespeichert wird. Deshalb greifen wir auch auf den ersten (und in den meisten Fällen einzigen Wert) mittels $matches[0] zu. Nun geben wir mit return noch den Inhalt von $matches[0] zurück (die gültige Email Adresse). Die Variable $mailcheck, enthält entweder die Email Adresse oder false.</p>
<h2>Komplett funktionsfähiges Skript um Email Adresse zu überprüfen</h2>
<p>Um unser <strong>PHP Email Adresse Prüfen</strong> Skript noch im Einsatz zu zeigen hier ein kompletter funktionierender Code, welchen man auch <a href="/beispiele/email_pruefen/email.php" target="_blank">hier testen</a> kann. </p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> mail_pruefen<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$adresse</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/empty"><span style="color: #000066;">empty</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$adresse</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// Wenn leer</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>; <span style="color: #808080; font-style: italic;">// Funktion beenden</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/* Überprüfen */</span>
	<span style="color: #0000ff;">$regex</span> = <span style="color: #ff0000;">'§[<span style="color: #000099; font-weight: bold;">\w</span>-.]{1,}@[<span style="color: #000099; font-weight: bold;">\w</span>-]{3,}<span style="color: #000099; font-weight: bold;">\.</span>[<span style="color: #000099; font-weight: bold;">\w</span>-]{2,3}§'</span>;
	<a href="http://www.php.net/preg_match"><span style="color: #000066;">preg_match</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$regex</span>, <span style="color: #0000ff;">$adresse</span>, <span style="color: #0000ff;">$matches</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/empty"><span style="color: #000066;">empty</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$matches</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// Wenn keine Email</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>; <span style="color: #808080; font-style: italic;">// Funktion beenden</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/strlen"><span style="color: #000066;">strlen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$matches</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>!=<a href="http://www.php.net/strlen"><span style="color: #000066;">strlen</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$adresse</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>; <span style="color: #808080; font-style: italic;">// Funktion beenden</span>
&nbsp;
	<span style="color: #b1b100;">return</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$matches</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #0000ff;">$mailcheck</span> = mail_pruefen<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_POST</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;email&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;form action=<span style="color: #ff0000;">&quot;&quot;</span> method=<span style="color: #ff0000;">&quot;post&quot;</span>&gt;
Email:
&lt;input name=<span style="color: #ff0000;">&quot;email&quot;</span> type=<span style="color: #ff0000;">&quot;text&quot;</span> value=<span style="color: #ff0000;">&quot;&lt;?php echo $_POST[&quot;</span>email<span style="color: #ff0000;">&quot;] ?&gt;&quot;</span> /&gt;
&lt;input type=<span style="color: #ff0000;">&quot;submit&quot;</span> value=<span style="color: #ff0000;">&quot;Prüfen&quot;</span> /&gt;
&lt;/form&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$mailcheck</span><span style="color: #66cc66;">&#41;</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Gültige Email Adresse&quot;</span>;
	<span style="color: #b1b100;">else</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Ungültige Email Adresse&quot;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p>Viel Spam bei <strong>Überprüfen deiner Email Adresse mit PHP</strong>. Diese Funktion kann ganz einfach eingebunden werden, solltest du jedoch trozdem Fragen dazu haben melde dich einfach hier.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.homepage-hilfe.org/php-email-adresse-auf-gultigkeit-uberprufen/feed</wfw:commentRss>
		</item>
		<item>
		<title>Mit PHP Aufrunden, Abrunden oder mathematisch richtig Runden</title>
		<link>http://www.homepage-hilfe.org/php-aufrunden-abrunden-mathematisch-runden</link>
		<comments>http://www.homepage-hilfe.org/php-aufrunden-abrunden-mathematisch-runden#comments</comments>
		<pubDate>Thu, 29 May 2008 14:10:01 +0000</pubDate>
		<dc:creator>Leichti</dc:creator>
		
		<category><![CDATA[PHP Tipps und Tricks]]></category>

		<category><![CDATA[abrunden]]></category>

		<category><![CDATA[aufrunden]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[runden]]></category>

		<category><![CDATA[zahlen]]></category>

		<guid isPermaLink="false">http://www.homepage-hilfe.org/?p=18</guid>
		<description><![CDATA[Oft muss man Zahlen aufrunden, abrunden, oder mathematisch korrekt runden. PHP bietet hier 3 Funktionen an:


round() - mathematisch Runden
ceil() - Aufrunden
floor() - Abrunden

Diese Rundungsfunktionen sollten eigentlich selbst erklärend sein, doch ich werde sie hier anhand einiger Beispiele erklären. Fangen wir mit dem Aufrunden an:
PHP Aufrunden
Hierbei rundet die Funktion ceil() einen Fließkommawert auf die nächstgrößere Ganzzahl [...]]]></description>
			<content:encoded><![CDATA[<p>Oft muss man Zahlen aufrunden, abrunden, oder mathematisch korrekt runden. PHP bietet hier 3 Funktionen an:<br />
<span id="more-18"></span></p>
<ul>
<li>round() - <strong>mathematisch Runden</strong></li>
<li>ceil() - <strong>Aufrunden</strong></li>
<li>floor() - <strong>Abrunden</strong></li>
</ul>
<p>Diese Rundungsfunktionen sollten eigentlich selbst erklärend sein, doch ich werde sie hier anhand einiger Beispiele erklären. Fangen wir mit dem Aufrunden an:</p>
<h2>PHP Aufrunden</h2>
<p>Hierbei rundet die Funktion ceil() einen Fließkommawert auf die nächstgrößere Ganzzahl auf. Anhand der Beispiele dürfte dies verständlich dargestellt sein</p>
<pre class="php">&nbsp;
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/ceil"><span style="color: #000066;">ceil</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2.25</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// rundet auf 3 auf</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/ceil"><span style="color: #000066;">ceil</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2.9</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// 3</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/ceil"><span style="color: #000066;">ceil</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">225.001</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// 226</span>
&nbsp;</pre>
<h2>PHP Abrunden</h2>
<p>Hierbei rundet die Funktion floor() einen Fließkommawert auf die nächstkleinere Ganzzahl ab. Anhand der Beispiele dürfte dies verständlich dargestellt sein</p>
<pre class="php">&nbsp;
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/floor"><span style="color: #000066;">floor</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2.25</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// rundet auf 2 ab</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/floor"><span style="color: #000066;">floor</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2.9</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// 2</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/floor"><span style="color: #000066;">floor</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">225.001</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// 225</span>
&nbsp;</pre>
<h2>Mathematisch korrektes runden mit PHP</h2>
<p>Mit der Funktion round() rundet PHP mathematisch korrekt. Es wird ab 5 aufgerunden, ansonsten abgerundet. Die Funktion round($zahl, $kommastellen) hat 2 Parameter, wobei nur der Erste($zahl) notwendig ist, $kommastellen ist als Standart 0. Einige Beispiele dürften diese Funktion verständlich erklären:</p>
<pre class="php">&nbsp;
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/round"><span style="color: #000066;">round</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">14.4</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Gibt 14 aus</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/round"><span style="color: #000066;">round</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">14.5</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// Gibt 15 aus</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/round"><span style="color: #000066;">round</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">14.4</span>, <span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// Gibt 10 aus</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <a href="http://www.php.net/round"><span style="color: #000066;">round</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">123.1234</span>, <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">// Gibt 123.23 aus</span>
&nbsp;</pre>
<p>Wie man also sehen kann, kann der Parameter der für die Kommastellen zuständig ist auch negativ sein.   So ist der Parameter z.B: -1 wird auf volle Zehner gerundet, bei -2 auf volle Hunderter usw.</p>
<p>Ich hoffe ich konnte dir das <strong>Runden mittels PHP</strong> einigermaßen verständlich erklären und wünsche viel Spaß beim <strong>Aufrunden bzw Abrunden mit PHP</strong> <img src='http://www.homepage-hilfe.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.homepage-hilfe.org/php-aufrunden-abrunden-mathematisch-runden/feed</wfw:commentRss>
		</item>
		<item>
		<title>Blätterfunktion mit PHP und mySQL.</title>
		<link>http://www.homepage-hilfe.org/blaetterfunktion-mit-php-und-mysql</link>
		<comments>http://www.homepage-hilfe.org/blaetterfunktion-mit-php-und-mysql#comments</comments>
		<pubDate>Sun, 06 Jan 2008 13:56:32 +0000</pubDate>
		<dc:creator>Leichti</dc:creator>
		
		<category><![CDATA[PHP Tipps und Tricks]]></category>

		<category><![CDATA[blätterfunktion]]></category>

		<category><![CDATA[gästebuch]]></category>

		<category><![CDATA[MYSQL]]></category>

		<category><![CDATA[newsskript]]></category>

		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.homepage-hilfe.org/archives/blatterfunktion-mit-php-und-mysql</guid>
		<description><![CDATA[In Gästebüchern, Newsskript etc. ist es sehr oft sinnvoll eine PHP Blätterfunktion einzubauen. Man sollte mittels PHP bzw mySQL die Ausgabe auf mehrere Seiten verteilen und somit übersichtlicher gestallten. Um eine Blätterfunktion mit PHP und mySQL zu realisieren ist prinzipiell nur eine einzige mySQL Funktion nötig...

Das Stichwort für eine funktionierende Blätterfunktion lautet LIMIT. LIMIT gibt [...]]]></description>
			<content:encoded><![CDATA[<p>In Gästebüchern, Newsskript etc. ist es sehr oft sinnvoll eine PHP Blätterfunktion einzubauen. Man sollte mittels PHP bzw mySQL die Ausgabe auf mehrere Seiten verteilen und somit übersichtlicher gestallten. Um eine Blätterfunktion mit PHP und mySQL zu realisieren ist prinzipiell nur eine einzige mySQL Funktion nötig...<br />
<span id="more-17"></span></p>
<p>Das Stichwort für eine funktionierende Blätterfunktion lautet LIMIT. LIMIT gibt eine gewisse Datenmenge x ab dem Eintrag y aus! Dies können wir optimal nutzen um unsere Blätterfunktion für PHP zu erstellen.</p>
<p>So genug geredet so sieht das ganze nun erst einmal als PHP-Code aus!</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> limitierte_ausgabe<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$anfang</span>, <span style="color: #0000ff;">$eintrage_lesen</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<a href="http://www.php.net/mysql_connect"><span style="color: #000066;">mysql_connect</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;localhost, username, passwort&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<a href="http://www.php.net/mysql_select_db"><span style="color: #000066;">mysql_select_db</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;tabelle&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #0000ff;">$sql</span> = <span style="color: #ff0000;">'SELECT*
		FROM guestbook
		ORDER BY datum desc
		LIMIT '</span>.<span style="color: #0000ff;">$anfangen</span>.<span style="color: #ff0000;">', '</span>.<span style="color: #0000ff;">$eintrage_lesen</span>;
&nbsp;
	<span style="color: #0000ff;">$query</span> = <a href="http://www.php.net/mysql_query"><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$row</span> = <a href="http://www.php.net/mysql_fetch_assoc"><span style="color: #000066;">mysql_fetch_assoc</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0000ff;">$gaestebuchausgabe</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$row</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$gaestebuchausgabe</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>So dies währe jetzt eigentlich schon eine Funktion die uns eine PHP bzw mySQL Blätterfunktion ermöglicht, doch wie wendet man diese nun an?</p>
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> limitierte_ausgabe<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$auslesen_beginnen</span>, <span style="color: #0000ff;">$eintrage_lesen</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<a href="http://www.php.net/mysql_connect"><span style="color: #000066;">mysql_connect</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;localhost, username, passwort&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<a href="http://www.php.net/mysql_select_db"><span style="color: #000066;">mysql_select_db</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;tabelle&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #0000ff;">$sql</span> = <span style="color: #ff0000;">'SELECT*
		FROM guestbook
		ORDER BY datum desc
		LIMIT '</span>.<span style="color: #0000ff;">$auslesen_beginnen</span>.<span style="color: #ff0000;">', '</span>.<span style="color: #0000ff;">$eintrage_lesen</span>;
&nbsp;
	<span style="color: #0000ff;">$query</span> = <a href="http://www.php.net/mysql_query"><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$sql</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$row</span> = <a href="http://www.php.net/mysql_fetch_assoc"><span style="color: #000066;">mysql_fetch_assoc</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0000ff;">$gaestebuchausgabe</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$row</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$gaestebuchausgabe</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">$eintraege_seite</span> = <span style="color: #cc66cc;">10</span>; <span style="color: #808080; font-style: italic;">/// 10 Einträge/Seite</span>
<span style="color: #0000ff;">$aktuelle_seite</span> = <span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;page&quot;</span><span style="color: #66cc66;">&#93;</span>;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$_GET</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;page&quot;</span><span style="color: #66cc66;">&#93;</span>&gt;=<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">/// Wenn die Seite nicht größer oder gleich 1 ist</span>
		<span style="color: #0000ff;">$aktuelle_seite</span> = <span style="color: #cc66cc;">1</span>; <span style="color: #808080; font-style: italic;">/// Soll sie 1 sein</span>
&nbsp;
<span style="color: #0000ff;">$auslesen_beginnen</span> = <span style="color: #0000ff;">$eintraege_seite</span>*<span style="color: #0000ff;">$aktuelle_seite</span> - <span style="color: #0000ff;">$eintraege_seite</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">/* Und nun nur noch die Funktion aufrufen */</span>
<span style="color: #0000ff;">$ausgabewerte</span> = limitierte_ausgabe<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$auslesen_beginnen</span>, <span style="color: #0000ff;">$eintraege_seite</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Rufen wir jetzt unsere Funktion limitierte_ausgabe auf, so müssen wir 2 Parameter eingeben ($auslesen_beginnen, $eintraege_seite), diese werden dann an unsere mySQL Funktion limit weitergegeben, um eben nur eine gewisse Anzahl an Einträge auszulesen! </p>
<p>Wie ja bekannt ist gibt mysql_fetch_assoc($query) ja eine Zeile nach der Anderen aus. Mit LIMIT werden jedoch nicht immer alle Zeilen in unserer Datenbank angesprochen, sondern nur eine gewisse Anzahl beginnend von dem Eintrag x von dennen die normal ausgelesen werden würden! </p>
<p><strong>Ein kleines Beispiel:</strong><br />
Wir haben eine Gästebuchdatenbank mit 20 Einträgen. Wenn wir jetzt nur die ersten 10 Einträge auslesen wollen, müssen wir mit LIMIT angeben von wo weg, bis wo hin, hier speziell <strong>LIMIT 0,10</strong> so. Wir wollen also vom ersten Beitrag (0) weg, 10 Beiträge auslesen! Wenn wir jetzt die Einträge 10-20 anzeigen möchten, so müssen wir ganz einfach <strong>LIMIT 10,10</strong> angeben. Dies heist jetzt, es werden vom 10ten Eintrag weg 10 weitere Einträge ausgelesen!</p>
<p>Was nun noch fehlt ist eine Ausgabe der Seiten. Wir lesen mittels $_GET["page"] aus auf welcher Seite wir gerade sind. Somit müssen wir nun einfach mittels einer Schleife die Links zu den Seiten ausgeben. Vorher muss nur noch geprüft werden wie viele Seiten wir haben, dies machen wir mittels mySQL, wir schauen wie viele Datensätze vorhanden sind, dividieren diese durch die Anzahl an Einträge/ Seite und runden diese Zahl auf! Fertig...</p>
<pre class="php">&nbsp;
<span style="color: #0000ff;">$query</span> = <a href="http://www.php.net/mysql_query"><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'SELECT COUNT(*) as zeilen FROM guestbook'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$row</span> = <a href="http://www.php.net/mysql_fetch_assoc"><span style="color: #000066;">mysql_fetch_assoc</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$zeilen</span> = <span style="color: #0000ff;">$row</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;zeilen&quot;</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #0000ff;">$seiten</span> = <a href="http://www.php.net/ceil"><span style="color: #000066;">ceil</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$zeilen</span>/<span style="color: #0000ff;">$eintraege_seite</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span>=<span style="color: #cc66cc;">1</span>;<span style="color: #0000ff;">$i</span>&lt;=<span style="color: #0000ff;">$seiten</span>;<span style="color: #0000ff;">$i</span>++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>?page=&quot;</span>. <span style="color: #0000ff;">$i</span> .<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span>. <span style="color: #0000ff;">$i</span> .<span style="color: #ff0000;">&quot;&lt;/a&gt; &quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>Und das war eigentlich schon alles um eine <strong>PHP Blätterfunktion</strong> mit mySQL Datenbank zu programmieren. Solltest du Fragen haben oder etwas unverständlich erklärt sein schreib bitte einfach einen Kommentar, ich werde innerhalb von 24 Stunden darauf antworten!</p>
<p>Viel spaß mit eurer eigenen <strong>PHP Blätterfunktion</strong>! <img src='http://www.homepage-hilfe.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><em><strong>PS: Wenn hier etwas unverständlich erklärt ist, bitte meldet euch</strong><br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.homepage-hilfe.org/blaetterfunktion-mit-php-und-mysql/feed</wfw:commentRss>
		</item>
		<item>
		<title>Mit PHP Überprüfen ob eine Datenbank existiert</title>
		<link>http://www.homepage-hilfe.org/mit-php-uberprufen-ob-eine-datenbank-existiert</link>
		<comments>http://www.homepage-hilfe.org/mit-php-uberprufen-ob-eine-datenbank-existiert#comments</comments>
		<pubDate>Tue, 01 Jan 2008 22:23:02 +0000</pubDate>
		<dc:creator>Leichti</dc:creator>
		
		<category><![CDATA[PHP Tipps und Tricks]]></category>

		<category><![CDATA[Datenbank prüfen]]></category>

		<category><![CDATA[existiert]]></category>

		<category><![CDATA[MYSQL]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[Tabelle]]></category>

		<guid isPermaLink="false">http://www.alkohol-drogen.de/homepage-tools/archives/mit-php-uberprufen-ob-eine-datenbank-existiert</guid>
		<description><![CDATA[Oft, wenn ich kleinere oder größere Scripte schreibe ist es immer nervig die MYSQL Datenbank neu anzulegen, und dazu immer eine install Datei aufzurufen. Auch ist es dann für andere Leute, dennen man das Script zum Download anbietet, "nervig" das "Ding" zu installieren. Doch man kann hier ganz einfach ein bisschen Luxus einbauen. Indem man [...]]]></description>
			<content:encoded><![CDATA[<p>Oft, wenn ich kleinere oder größere Scripte schreibe ist es immer nervig die MYSQL Datenbank neu anzulegen, und dazu immer eine install Datei aufzurufen. Auch ist es dann für andere Leute, dennen man das Script zum Download anbietet, "nervig" das "Ding" zu installieren. Doch man kann hier ganz einfach ein bisschen Luxus einbauen. Indem man die Datenbank nur dann installiert, wenn sie vorhanden ist. </p>
<p><span id="more-15"></span></p>
<p>Grundsätzlich gibt es dafür jetzt zwei Möglichkeiten, einmal eine SQL Funktion und einmal mit Hilfe von PHP.<br />
Die erste Möglichkeit hierfür wäre, das Ganze mit Hilfe von if not exists (SQL Code) zu realisieren, das würde dann folgendermaßen aussehen.</p>
<pre class="php">&nbsp;
<a href="http://www.php.net/mysql_query"><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;CREATE TABLE IF NOT EXISTS
		tabelle (spalte spaltentyp, [...])&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>Die zweite, für mich schönere Lösung wäre mittels PHP zu überprüfen ob eine Tabelle in der Datenbank schon vorhanden ist. Dazu schreiben wir uns eine kleine Funktion die wir immer, wenn wir sie brauchen verwenden können.</p>
<pre class="php">&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> checktable<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$tablename</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #0000ff;">$query</span> = <span style="color: #ff0000;">&quot;SHOW TABLES LIKE &quot;</span>.<span style="color: #0000ff;">$tablename</span>;
		<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/mysql_num_rows"><span style="color: #000066;">mysql_num_rows</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/mysql_query"><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$query</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>mysql_num_rows(mysql_query("SHOW TABLES LIKE ".$tablename."")) gibt true bzw eine Zahl zurück, wenn die Tabelle mit dem Namen der in der Variable $tablename gespeichert ist existiert und false wenn diese Tabelle noch nicht Existent ist.</p>
<p>Diese Funktion können wir nun folgendermaßen aufrufen:</p>
<pre class="php">&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>checktable<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;News&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Tabelle News wurde bereits angelegt&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
	<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Tabelle News wurde noch nicht angelegt&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.homepage-hilfe.org/mit-php-uberprufen-ob-eine-datenbank-existiert/feed</wfw:commentRss>
		</item>
		<item>
		<title>Mit Hilfe von CSS Frames simulieren - Non-Scrolling-Regionen</title>
		<link>http://www.homepage-hilfe.org/mit-hilfe-von-css-frames-simulieren-non-scrolling-regionen</link>
		<comments>http://www.homepage-hilfe.org/mit-hilfe-von-css-frames-simulieren-non-scrolling-regionen#comments</comments>
		<pubDate>Sun, 30 Dec 2007 10:00:32 +0000</pubDate>
		<dc:creator>Leichti</dc:creator>
		
		<category><![CDATA[CSS]]></category>

		<category><![CDATA[frames]]></category>

		<category><![CDATA[include]]></category>

		<category><![CDATA[navigation fixieren]]></category>

		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://www.alkohol-drogen.de/homepage-tools/archives/mit-hilfe-von-css-frames-simulieren-non-scrolling-regionen</guid>
		<description><![CDATA[In einem anderen Kapitel habe ich beschrieben wie man mit Hilfe von PHP- Include fast alle vorteile von Frames nutzen kann, und hier möchte ich noch zeigen, dass es auch möglich ist, Bereiche mit CSS, ähnlich wie mit Frames, zu fixieren, sodass sie nicht mitzuscrollen (Eine sogenannte Non-Scrolling-Regionen)
Frames werden also in den meisten Fällen nur [...]]]></description>
			<content:encoded><![CDATA[<p class="newline">In einem <a href="archives/php-include-anstatt-frames">anderen Kapitel</a> habe ich beschrieben wie man mit Hilfe von PHP- Include fast alle vorteile von Frames nutzen kann, und hier möchte ich noch zeigen, dass es auch möglich ist, Bereiche mit CSS, ähnlich wie mit Frames, zu fixieren, sodass sie nicht mitzuscrollen (Eine sogenannte Non-Scrolling-Regionen)</p>
<p class="newline">Frames werden also in den meisten Fällen nur eingesetzt, um einen fixen<br />
Bereich zu haben, der nicht mit scrollt (Non-Scrolling-Region), oder um eine zentrale Navigationsliste zu haben, welche man bei Änderungen auch nur einmal ändern muss(siehe dazu <a href="archives/php-include-anstatt-frames">PHP-Include</a>). Hier möchte ich zeigen, wie so etwas auch ohne Frames funktioniert – aus der<br />
Überlegung heraus, dass es einfach zu schade ist, die zahlreichen Nachteile, vorallem die Suchmaschinenunfreundlichkeit, von Frames in Kauf zu nehmen, wenn das gewünschte Ziel auch anders erreichbar ist.</p>
<p><span id="more-12"></span></p>
<p>CSS kennt eine Positionierungseigenschaft <em>position:fixed</em>, welche mittels top, left, bottom und right absolut positioniert wird.<br />
<strong>Die CSS Datei fix.css</strong></p>
<pre class="css"><span style="color: #cc00cc;">#navigation</span> <span style="color: #66cc66;">&#123;</span>
position<span style="color: #3333ff;">:fixed</span>;
top<span style="color: #3333ff;">:<span style="color: #933;">1em</span></span>;
left<span style="color: #3333ff;">:<span style="color: #933;">1em</span></span>;
padding-right<span style="color: #3333ff;">:<span style="color: #933;">1em</span></span>;
border-right<span style="color: #3333ff;">:black</span> <span style="color: #993333;">solid</span> <span style="color: #933;">4px</span>;
<span style="color: #000000; font-weight: bold;">height</span>: <span style="color: #933;"><span style="color: #933;">100</span>%</span>;
<span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #cc00cc;">#EEE</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #cc00cc;">#content</span> <span style="color: #66cc66;">&#123;</span>
margin-left<span style="color: #3333ff;">:<span style="color: #933;">7em</span></span>;
margin-right<span style="color: #3333ff;">:<span style="color: #933;">1em</span></span>;
<span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #cc00cc;">#CCC</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>und die HTML datei</p>
<pre>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;
&quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;
&lt;html lang=&quot;de&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html;
charset=ISO-8859-1&quot;&gt;
&lt;title&gt;Fixer Bereich&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;fix.css&quot;&gt;
&lt;!--[if gte IE 5]&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;ie-fix.css&quot;&gt;
&lt;![endif]--&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;navigation&quot;&gt;
&lt;h1&gt;Navigation&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;&quot;&gt;Seite 2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;&quot;&gt;Seite 3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;&quot;&gt;Seite 4&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div id=&quot;content&quot;&gt;
&lt;h1&gt;Content&lt;/h1&gt;
&nbsp;
Content...
&lt;/div&gt;
&nbsp;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><a href="http://www.homepage-hilfe.org/beispiele/beispiel-css-noframes/schritt-1/">So, nun sieht das ganze erstmal so aus</a><br />
Das div-Element mit der id Navigation wird nun beim scrollen nicht mehr mitgescrollt. Allerdings gibt es leider auch den Internet Explorer, der position:fixed bis einschließlich Version 6 nicht kennt. Doch für den Internet gibt es ein Workaround, mit Hilfe von Javascript!</p>
<h2>Workaround für Internet Explorer bis Version 6</h2>
<p>Zuerst einmal ändern wir unsere eigentliche fix.css Datei.</p>
<pre class="css">body &gt;body &gt; <span style="color: #cc00cc;">#navigation</span> <span style="color: #66cc66;">&#123;</span>
position<span style="color: #3333ff;">:fixed</span>;
top<span style="color: #3333ff;">:<span style="color: #933;">20px</span></span>;
left<span style="color: #3333ff;">:<span style="color: #933;">20px</span></span>;
<span style="color: #000000; font-weight: bold;">width</span>: <span style="color: #933;">10em</span>;
border-right<span style="color: #3333ff;">:black</span> <span style="color: #993333;">solid</span> <span style="color: #933;">4px</span>;
<span style="color: #000000; font-weight: bold;">height</span>: <span style="color: #933;"><span style="color: #933;">100</span>%</span>;
<span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #cc00cc;">#EEE</span>;
<span style="color: #66cc66;">&#125;</span>
body &gt; <span style="color: #cc00cc;">#content</span> <span style="color: #66cc66;">&#123;</span>
margin-left<span style="color: #3333ff;">:<span style="color: #933;">12em</span></span>;
margin-right<span style="color: #3333ff;">:<span style="color: #933;">10px</span></span>;
<span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #cc00cc;">#CCC</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p class="newline">Geändert wird die Syntax der Selektoren dahingehend, dass von den CSS-2.0-spezifischen<br />
Adressierungsmöglichkeiten für Elemente Gebrauch gemacht wird. Diese werden vom<br />
Internet Explorer ebenfalls nicht erkannt. Als Ergebnis ignoriert dieser Browser die<br />
Formatdefinitionen für beide div-Bereiche komplett.<br />
Stattdessen bekommt der IE eine nur für ihn lesbare<br />
CSS-Datei spendiert. Dazu wird im HEAD-Bereich des HTML-Dokuments  folgendes notiert:</p>
<p><code><!--[if gte IE 5]></p>
<link rel="stylesheet" type="text/css" href="ie-fix.css">
<![endif]--></code></p>
<p>Der IE interpretiert dieses Kommentar im Quelltext, und liest seine <strong>ie-fix.css</strong> Datei.</p>
<pre class="css">html, body <span style="color: #66cc66;">&#123;</span>
overflow<span style="color: #3333ff;">:hidden</span>;
width<span style="color: #3333ff;">:<span style="color: #933;">100</span></span>%;
height<span style="color: #3333ff;">:<span style="color: #933;">100</span></span>%;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #cc00cc;">#navigation</span> <span style="color: #66cc66;">&#123;</span>
position<span style="color: #3333ff;">:absolute</span>;
top<span style="color: #3333ff;">:<span style="color: #933;">20px</span></span>;
left<span style="color: #3333ff;">:<span style="color: #933;">20px</span></span>;
padding-right<span style="color: #3333ff;">:<span style="color: #933;">20px</span></span>;
border-right<span style="color: #3333ff;">:black</span> <span style="color: #993333;">solid</span> <span style="color: #933;">4px</span>;
<span style="color: #000000; font-weight: bold;">height</span>: <span style="color: #933;"><span style="color: #933;">100</span>%</span>;
<span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #cc00cc;">#eee</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #cc00cc;">#content</span> <span style="color: #66cc66;">&#123;</span>
position<span style="color: #3333ff;">:absolute</span>;
top<span style="color: #3333ff;">:<span style="color: #933;">0px</span></span>;
left<span style="color: #3333ff;">:<span style="color: #933;">200px</span></span>;
margin-top<span style="color: #3333ff;">:<span style="color: #933;">20px</span></span>;
height<span style="color: #3333ff;">:expression</span><span style="color: #66cc66;">&#40;</span>document<span style="color: #6666ff;">.body</span><span style="color: #6666ff;">.clientHeight</span> - <span style="color: #933;">20</span> + <span style="color: #ff0000;">&quot;px&quot;</span><span style="color: #66cc66;">&#41;</span>;
width<span style="color: #3333ff;">:expression</span><span style="color: #66cc66;">&#40;</span>document<span style="color: #6666ff;">.body</span><span style="color: #6666ff;">.clientWidth</span> - <span style="color: #933;">200</span> + <span style="color: #ff0000;">&quot;px&quot;</span><span style="color: #66cc66;">&#41;</span>;
overflow<span style="color: #3333ff;">:auto</span>;
<span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #cc00cc;">#ccc</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p><a href="http://www.homepage-hilfe.org/beispiele/beispiel-css-noframes/schritt-2/">Nun sieht das ganze so aus</a>, im Firefox und Co, ist aber kein unterschied zu sehen</p>
<p class="newline">Zunächst wird für die Basiselemente html und body festgelegt, dass diese die volle Breite und Höhe einnehmen. Gleichzeitig wird bestimmt, dass Inhalte, die länger oder breiter sind, einfach abgeschnitten werden (overflow:hidden, Überfluss unsichtbar). Die beiden div-Bereiche werden daraufhin beide absolut positioniert. Bis auf die Art der Positionierung sind die Formatdefinitionen für den Bereich navigation die gleichen wie in der normalen CSS-Datei. Bei den Definitionen für content gibt es hingegen einige Unterschiede. Mit <strong>position:absolute</strong>, <strong>top</strong> und <strong>left</strong> muss dessen gewünschte Anfangsposition bestimmt werden, da er ja absolu