Hallo alle miteinander!!
Habe folgendes Problem!!!
Ich hab hier ein Upload script für bilder geschrieben welches mir die bilder Proportional verkleinert und dann abspeichert!
leider funktioniert dieses Script nicht! Wäre euch sehr verbunden wenn ihr mal schaun könntet wo der Fehler liegt!!
PHP-Code:
<?php
## Upload Formular! ##
######################
echo "
<form method=\"post\" action=\"\" enctype=\"multipart/form-data\" >
<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\">
<tr >
<td>Datei:</td>
<td><input type=\"file\" name=\"file1\" size=\"16\"></td>
</tr>
<tr >
<td></td>
<td><input type=\"submit\" value=\"Upload\"></td>
</tr>
</table>
</form>"; // Wichtig ist hier beim <form ... das: enctype=\"multipart/form-data\"
// Dem Dateiupload feld geben wir den namen file1 (wird später noch benötigt)
## Upload Funktion! ##
######################
if($_FILES['file1']['tmp_name'] != "") {
// Verzeichniss wo die Dateien hingeladen werden sollen:
// WICHTIG!! das Verzeichniss muss den chmod 777 besitzen!
$pfad = dirname(__FILE__);
$uploaddir = $pfad."/";
// Upload script:
if(move_uploaded_file($_FILES['file1']['tmp_name'], $uploaddir.$_FILES['file1']['name'])) { // hier wird die datei aus dem Temp. speicher vom Server in den von den von dir angegebenen Pfad verschoben (move..)
$dateiname = $_FILES['file1']['name']; // hier wird nochmal der dateiname in eine Variable gespeichert.
$dateipfad = $uploaddir.$dateiname; // hier das gesamte Pfad zur Datei!
$maxlen = 640;
$dateipfad_neu = dirname(__FILE__)."/";
$imgsize = array();
$imgsize = getimagesize($dateipfad);
$imgw = $imgsize[0];
$imgh = $imgsize[1];
$neww = $imgw;
$newh = $imgh;
if ($imgw < $imgh && $imgh > $maxlen) {
$neww = $imgh * $maxlen / $imgw;
$newh = $maxlen;
thumb($dateipfad, $dateipfad_neu, $neww, $newh, true); } else if ($imgw >
$imgh && $imgw > $maxlen) {
$neww = $maxlen;
$newh = $imgw * $maxlen / $imgh;
thumb($dateipfad, $dateipfad_neu, $neww, $newh, true); }
function thumb($filename, $destination, $th_width, $th_height, $forcefill)
{
list($width, $height) = getimagesize($filename);
$source = imagecreatefromjpeg($filename);
if($width > $th_width || $height > $th_height){
$a = $th_width/$th_height;
$b = $width/$height;
if(($a > $b)^$forcefill)
{
$src_rect_width = $a * $height;
$src_rect_height = $height;
if(!$forcefill)
{
$src_rect_width = $width;
$th_width = $th_height/$height*$width;
}
}
else
{
$src_rect_height = $width/$a;
$src_rect_width = $width;
if(!$forcefill)
{
$src_rect_height = $height;
$th_height = $th_width/$width*$height;
}
}
$src_rect_xoffset = ($width - $src_rect_width)/2*intval($forcefill);
$src_rect_yoffset = ($height - $src_rect_height)/2*intval($forcefill);
$thumb = imagecreatetruecolor($th_width, $th_height);
imagecopyresized($thumb, $source, 0, 0, $src_rect_xoffset,
$src_rect_yoffset, $th_width, $th_height, $src_rect_width, $src_rect_height);
imagejpeg($thumb,$destination);
}
}
echo "Datei wurde hochgeladen(".$dateipfad.")."; // Statusmeldung!
} else {
echo "Datei konnte nicht hochgeladen werden."; // Statusmeldung!
};
};
?>
folgender Fehler tritt immer auf:
controll thumb()
aber meiner meinung stimmt der code!!!
vielen dank für eure hilfe, mfg andi