meliah_rage: Bilderupload mit PHP - Hilfe???

Beitrag lesen

Hallo hab hier das Script gefunden und es klappt auch soweit, nur weiß ich nicht genau wie ich es anpassen kann? Es sollte folgendes möglich sein... wen man einen der Buttons klickt (Bild und Thumb) sollte erst das durchsuchen und speichern feld angeszeigt werden, außerdem soll die id an den bildernamen mit angehängt werden oder besser gleich über den gewählten Button mit übernommen werden. Leider bin ich noch Anfänger in sachen PHP und wäre echt dankbar wen Ihr mir hier helfen könntet!?!

der Code im moment sieht so aus: /////////////////////////////////////////////////////////////////// Code:

<?php session_start();

require_once('funktionen.lib.php');

$verbindung = starteDatenbank();

$id = $_REQUEST['id'];

$ausgabe = reisenAuslesen($verbindung);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>    <meta http-equiv="content-type" content="text/html; charset=utf-8">     <meta http-equiv="cache-control" content="no-cache" />

<title>Bilder Upload</title>

<link rel="stylesheet" type="text/css" media="screen" href="styles.css" />     <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"> </head>

<body>

<div id="header"></div>

<?php include ('menu.php'); ?>

<?php if($_POST["action"]){ $filename = "";

$path = "uploadbilder/"; // Url zum Speicherordner der großen Bilder $thumb_path = "uploadbilder/thumb/"; // Url zum Speicherordner der Vorschaubilder $config_width = "320"; // Bildbreite max. bei großem Bild $config_height = "240"; // Bildhöhe max. bei großem Bild $config_thumb_width = "80"; // Bildbreite max. bei Vorschaubild $config_thumb_height = "60"; // Bildhöhe max. bei Vorschaubild $resizequality = "70"; // Bildkompressionsrate 0-100 $deindomain = "http://localhost/rhagn/mitarbeiterbereich/mitarbeiter/upload1.php";  // Domain

if ($HTTP_POST_FILES['userfile']['tmp_name']<> 'none') {

$filename = $HTTP_POST_FILES['userfile']['name'];     $filetype = $HTTP_POST_FILES['userfile']['type'];     $filetmp = $HTTP_POST_FILES['userfile']['tmp_name'];     $path_parts = pathinfo($file);     $filename = "reise_" . $id . "." . $path_parts["extension"];     $dest = $path.$filename;     copy($temp, $dest);

switch ($filetype)    {       case 'image/jpeg':       case 'image/jpg':       case 'image/pjpeg':

$pic_filetype = '.jpg';          break;

case 'image/png':       case 'image/x-png':

$pic_filetype = '.png';          break;

case 'image/gif':

$pic_filetype = '.gif';          break;       default:          die("Falsches Dateiformat. Nur JPEG, GIF oder PNG erlaubt!");    }

srand((double)microtime()*1000000);   //version 4.2.0 of PHP

do    {       $pic_filename = md5(uniqid(rand())) . $pic_filetype;    }    while( file_exists($path . $pic_filename) );

$ini_val = ( @phpversion() >= '4.0.0' ) ? 'ini_get' : 'get_cfg_var';

if ( @$ini_val('open_basedir') != '' )    {       if ( @phpversion() < '4.0.3' )       {          die("open_basedir is set and your PHP version does not allow move_uploaded_file<br /><br />Please contact your server admin");       }

$move_file = 'move_uploaded_file';    }    else    {       $move_file = 'copy';    }

$move_file($filetmp, $path . $pic_filename);

@chmod($path . $pic_filename, 0777);

$pic_size = getimagesize($path . $pic_filename);

$pic_width = $pic_size[0];    $pic_height = $pic_size[1];

if($pic_filetype != '.gif')    {       $gd_errored = FALSE;

switch ($pic_filetype)       {          case '.jpg':             $read_function = 'imagecreatefromjpeg';             break;          case '.png':             $read_function = 'imagecreatefrompng';             break;       }

$src = @$read_function($path  . $pic_filename);

if (!$src)       {          $gd_errored = TRUE;          $pic_thumbnail = '';       }       else if( ($pic_width > $config_thumb_width) or ($pic_height > $config_thumb_height) )       {          // Resize          if ($pic_width > $pic_height)          {             $thumbnail_width = $config_thumb_width;             $thumbnail_height = $config_thumb_width * ($pic_height/$pic_width);          }          else          {             $thumbnail_height = $config_thumb_height;             $thumbnail_width = $config_thumb_height * ($pic_width/$pic_height);          }

$thumbnail = @imagecreatetruecolor($thumbnail_width, $thumbnail_height);

$resize_function = 'imagecopyresampled';

@$resize_function($thumbnail, $src, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $pic_width, $pic_height);       }       else       {          $thumbnail = $src;       }

if (!$gd_errored)       {          $pic_thumbnail = $pic_filename;

switch ($pic_filetype)          {             case '.jpg':                @imagejpeg($thumbnail, $thumb_path . $pic_thumbnail, $resizequality);                break;             case '.png':                @imagepng($thumbnail, $thumb_path . $pic_thumbnail);                break;          }

@chmod($thumb_path . $pic_thumbnail, 0777);

}

}

if($pic_filetype != '.gif')   {     $gd_errored = FALSE;

switch ($pic_filetype)     {       case '.jpg':         $read_function = 'imagecreatefromjpeg';         break;       case '.png':         $read_function = 'imagecreatefrompng';         break;     }

$src = @$read_function($path  . $pic_filename);

if (!$src)     {       $gd_errored = TRUE;       $pic_resize = '';     }     else if( ($pic_width > $config_width) or ($pic_height > $config_height) )     {       // Resize       if ( (($pic_width / $pic_height) > ($config_width / $config_height)) )       {         $resize_width = $config_width;         $resize_height = $config_width * ($pic_height/$pic_width);       }       else       {         $resize_height = $config_height;         $resize_width = $config_height * ($pic_width/$pic_height);       }

$resize = @imagecreatetruecolor($resize_width, $resize_height);

$resize_function = 'imagecopyresampled';

@$resize_function($resize, $src, 0, 0, 0, 0, $resize_width, $resize_height, $pic_width, $pic_height);     }     else     {       $resize = $src;     }

if (!$gd_errored)     {       $pic_resize = $pic_filename;

switch ($pic_filetype)       {         case '.jpg':           @imagejpeg($resize, $path . $pic_resize, $resizequality);           break;         case '.png':           @imagepng($resize, $path . $pic_resize);           break;       }

@chmod($path . $pic_resize, 0777);

}

}     print '<div style="color:gray;">Datei ist auf den Server!<br /><br />';     print '<a href="'.$_SERVER['PHP_SELF'].'">Noch ein Bild auf den Server laden...</a><br /><br /></div>';

} } else { ?>

<form method="post" enctype="multipart/form-data" action="<?php print $_SERVER["PHP_SELF"]; ?>">         <input type="hidden" name="id" value="<?php print $id ?>">     <br />         <strong>Bilder Upload</strong> <br />     <br />         <input name="userfile" type="file" size=40>     <br />     <br />         <input type="submit" name="action" value="Speichern">     <br />     <br />     </form> <?  } ?>

<?php

$anzahl_reisen = count($ausgabe);     if($anzahl_reisen){         print "<table id='ausgabeTabelle' cellspacing='5' cellpadding='5'>";

print "<tr>";                 print "<th style='border: 1px solid gray;'>" . 'Reise ID' . "</th>";                 print "<th style='border: 1px solid gray;'>" . 'Schiff' . "</th>";                 print "<th style='border: 1px solid gray;'>" . 'Reederei' . "</th>";                 print "<th style='border: 1px solid gray;'>" . 'Reiseziel' . "</th>";                 print "<th style='border: 1px solid gray;'>" . 'Starttermin' . "</th>";                 print "<th style='border: 1px solid gray;'>" . 'Thumbnail' . "</th>";                 print "<th style='border: 1px solid gray;'>" . 'Bild' . "</th>";             print "</tr>";

for($i=0; $i<$anzahl_reisen; $i++){             print "<tr>";                 print "<td style='border: 1px solid gray;'>" . $ausgabe[$i]['id'] . "</td>";                 print "<td style='border: 1px solid gray;'>" . $ausgabe[$i]['schiffsname'] . "</td>";                 print "<td style='border: 1px solid gray;'>" . $ausgabe[$i]['veranstaltername'] . "</td>";                 print "<td style='border: 1px solid gray;'>" . $ausgabe[$i]['fahrtgebietname'] . "</td>";                 print "<td style='border: 1px solid gray;'>" . strftime('%d %m %Y', $ausgabe[$i]['starttermin']) . "</td>";                 print "<td style='border: 1px solid gray;'><a href='upload.php?aktion=thumbUpload&id=".$ausgabe[$i]['id']."'> Thumb  </a></td>";                 print "<td style='border: 1px solid gray;'><a href='upload.php?aktion=bildUpload&id=".$ausgabe[$i]['id']."'> Bild </a></td>";             print "</tr>";         }         print "</table>";     } ?>

<div id="footer"></div>

</body> </html> //////////////////////////////////////////////////////////////////

es werden dabei reisen aus der Datenbank ausgelesen und dies sollen ein thumb vorschau bild erhalten und das große bild soll dann zur gewählten Reise auf der HP erscheinen... aber es würde schon reichen wen mir jemand beim korrigieren des vorhanden Codes helfen würde!

Vielen dank in voraus Grüße aus Nürnberg