Werbung - Gast

Bildupload


Keywords for this topic
beschreibung, bild, name, type, div, files, error, mysql, bildname, image, return, width, align, echo, fail

Bildupload

Unread postby Thomas » Wed 12. Aug 2009, 21:19

Code: Select all
<?php
#--------------------------------------------------------------------------------#
#                  \||/                                                          #
#                  |  @___oo                                                     #
#        /\  /\   / (__,,,,|                                                     #
#       ) /^\) ^\/ _)                                                            #
#       )   /^\/   _)                 _/_/_/_/  _/_/_/_/    _/_/_/    _/_/       #       
#       )   _ /  / _)                      _/  _/        _/        _/    _/      #       
#   /\  )/\/ ||  | )_)                    _/  _/_/_/    _/  _/_/  _/    _/       #       
#  <  >      |(,,) )__)            _/    _/  _/        _/    _/  _/    _/        #       
#   ||      /    \)___)\            _/_/    _/_/_/_/    _/_/_/    _/_/           #
#   | \____(      )___) )___                                                     #
#    \______(_______;;; __;;;                                                    #
#                                                                                #
#----------------------------------------------------------------by Thomas---------#
error_reporting(E_ALL);

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//                          Datenbank verbindung                                //
//                                                                                //
//////////////////////////////////////////////////////////////////////////////////
   
function db_connect()
    {
    $hostname = "localhost";
    $database = "datenbank"; // deine Datenbank
    $username = "benutzername"; // dein Benutzername
    $password = "passwort"; // dein Passwort
   
    $result = mysql_pconnect($hostname, $username, $password)
            or trigger_error(mysql_error(),E_USER_ERROR);
   
    mysql_select_db($database, $result);
   
    return $result;
    }
   
//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//                             Fehler Ausgabe                                   //
//                                                                                //
//////////////////////////////////////////////////////////////////////////////////

function fail($string)
    {
    echo "<div align=\"center\">".$string."<p>&nbsp;</p><a href=\"javascript:history.back()\">Zur&uuml;ck</a></div>";
    return;
    }
   
//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//                            Der Bilderupload                                  //
//                                                                                //
//////////////////////////////////////////////////////////////////////////////////

$con = db_connect();

if (isset($_POST['send']))
    {
    $beschreibung = $_POST['beschreibung'];
    $beschreibung = trim($beschreibung);                 // Hier kannst du bestimmen was alles gespeichert wird.
    $beschreibung = strip_tags($beschreibung);           // ob html gespeichert werden darf oder nicht etc.
    $beschreibung = htmlentities($beschreibung);
    $beschreibung = stripslashes($beschreibung);
    $beschreibung = nl2br($beschreibung);
    $endung =substr(strrchr($_FILES['bild']['name'], '.'), 1);
    $type = $_FILES['bild']['type'];
    $uploadpfad = $_SERVER['DOCUMENT_ROOT']."/benutzerbilder/";

    if($_FILES['bild']['size'] > 102400)
        {
        fail("Ihr Bild ist zu gro&szlig;. Es sind max. 100kb erlaubt.");
        return;
        }   
       
    if ($type != 'image/jpeg' AND $type != 'image/jpg' AND $type != 'image/pjpeg' AND $type != 'image/png')
        {
        fail("Ihr Bild darf nur im Format .png oder .jpg sein!");
        return;
        }
       
    if($_FILES['bild']['name']!="")
        {
        $bildname = $_FILES['bild']['name'] = time().".".$endung;  // Hier bekommt dein Bild einen neuen Namen, damit keine Doppelnamen vorhanden sind.
        }
       
    if (move_uploaded_file($_FILES['bild']['tmp_name'], $uploadpfad.$bildname))
        {
        chmod ($uploadpfad.$bildname, 0644); // Hier kannst du die Bildrechte ändern.
        $insert = "INSERT INTO bilder (bild, beschreibung) VALUES ('".$bildname."', '".$beschreibung."')";
        $query = mysql_query($insert, $con) or die(mysql_error());
       
        echo "Ihre Daten wurden gespeichert!";
        }
    }
else
  {
  echo '<form action="upload.php" method="post" enctype="multipart/form-data" name="upload" id="upload">
          <table width="100%"  border="0" bgcolor="#EEEEEE">
            <tr>
              <td width="30%">Bild:</td>
              <td width="70%"><div align="left">
                  <input name="bild" type="file" size="30" />
        &nbsp; Bildtypen: .jpg, .png&nbsp;&nbsp; <br />
                  <br />
                  <strong>! ! ! ACHTUNG ! ! !</strong><br />
                  Max. Bildgr&ouml;&szlig;e ist 100 kb.</div></td>
            </tr>
            <tr>
              <td>Beschreibung:</td>
              <td><div align="left">
                  <textarea name="beschreibung" cols="50" rows="6"></textarea>
                </div></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><input type="submit" name="Submit" value="Bild Speichern" />
                <input name="send" type="hidden" id="send" value="1" /></td>
            </tr>
          </table>
        </form>';
    }
?>
Mfg Thomas
User avatar
Thomas
Administrator
Administrator
 
Users InformationUsers Information Users Information
 

Show post links

Offline

Werbung - Mitte

 

Share on ...

Share on FacebookShare on TwitterShare on TuentiShare on SonicoShare on FriendFeedShare on OrkutShare on DiggShare on MySpaceShare on DeliciousShare on Technorati

Werbung - Allgemein


Who is online

Users browsing this forum: No registered users and 0 guests

Return to Scriptbörse: Angebote

Who is online

Users browsing this forum: No registered users and 0 guests

cron

User Control Panel

Login

Who is online

In total there are 0 users online :: 0 registered, 0 hidden, 0 bots and 0 guests (based on users active over the past 60 minutes)
Most users ever online was 2918 on Sun 19. Jan 2020, 07:36

Users browsing this forum: No registered users and 0 guests
TWCportal DE | TWCmail DE & TWCmail EU | Help-Book DE & Help-Book EU | PHP-Wolf | Online-ABC & OnlineABC | Web-Hacks


Usemax-Advertisement | Zanox - Das Werbenetzwerk | TWCgames DE