Hallo Leute,
Nach langer PHP-Inaktivität muss ich für jemanden mal etwas anpassen und wollte ein Script das ich an anderer Stelle nutze auch dafür verwenden.
Nun finde ich gerade meinen Fehler nicht.
Auf einer HP habe ich ein IMG upload sowie ein Newsscript laufen.
Im aktuellen Anwendungsfall dachte ich mir ich könnte beides ja zusammen in ein <form> packen.
Formular:
Script:
MySQL_Error:
Warning: move_uploaded_file(pics/upload/BILD0861.JPG) [function.move-uploaded-file]: failed to
open stream: No such file or directory in
C:\xampp\htdocs\Projekte\hildes\admin.php on line
84
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to
move 'C:\xampp\tmp\php3741.tmp' to 'pics/upload/BILD0861.JPG' in
C:\xampp\htdocs\Projekte\hildes\admin.php on line
84
Warning: getimagesize(pics/upload/BILD0861.JPG) [function.getimagesize]: failed to open stream:
No such file or directory in C:\xampp\htdocs\Projekte\hildes\admin.php on
line 85
Vielen Dank im Voraus!
Nach langer PHP-Inaktivität muss ich für jemanden mal etwas anpassen und wollte ein Script das ich an anderer Stelle nutze auch dafür verwenden.
Nun finde ich gerade meinen Fehler nicht.
Auf einer HP habe ich ein IMG upload sowie ein Newsscript laufen.
Im aktuellen Anwendungsfall dachte ich mir ich könnte beides ja zusammen in ein <form> packen.
Formular:
PHP:
<form action="admin.php" method="post" enctype="multipart/form-data">
<input type="text" class="feld" style="width:350px" name="producttitle" value="Titel">
<textarea rows="8" class="feld" style="width:350px" name="producttext">TEXT</textarea><br>
<input name="thefile" type="file">
<input type="reset" value="Abbrechen" class="send" style="width:35%" /> <input type="submit" name="upload" class="send" value="Upload" style="width:35%" />
</form>
Script:
PHP:
//Datei Hochladen
if(isset($_POST['upload']))
{
$file = $_FILES['thefile']['tmp_name'];
$imgname = $_FILES['thefile']['name'];
if(isset($file))
{
$imgPath = "pics/upload/";
$max_width = 600;
move_uploaded_file($file, $imgPath.$imgname);
$img = getimagesize($imgPath.$imgname);
$imgX = $img[0];
$imgY = $img[1];
$type=image_type_to_mime_type($img[2]);
if($type=='image/jpeg')
{
//Erstelle Bild von JPG
$src_img = imagecreatefromjpeg($imgPath.$imgname);
}
elseif($type=='image/png')
{
//Erstelle Bild von PNG
$src_img = imagecreatefrompng($imgPath.$imgname);
}
elseif($type=='image/gif')
{
//Erstelle Bild von Gif
$src_img = imagecreatefromgif($imgPath.$imgname);
}
else
{
//Bild typ ist ungueltig!
$content.='<box class="error"> Der Bildtyp "'.$type.'" wird nicht unterstützt! Bitte nur PNG,JPG und GIF Bilder hochladen!</box>';
exit;
}
if($imgX <= $max_width)
{
$new_width = $imgX;
$new_height = $imgY;
echo "!!!$new_width!!!!!!!!!$new_height!!!!!";
}
else //Bild breiter 600px
{
$convert = ($max_width/$imgX);
$new_width = $max_width;
$new_height = ceil($imgY*$convert);
echo "???$new_width???????$new_height??";
}
//$dst_img = imagecreatetruecolor($new_width,$new_height);
$dst_img = imagecreatetruecolor($new_width,$new_height);
imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $new_width, $new_height, $imgX, $imgY);
//imageCopyResampled($dst_img,$src_img,0,0,0,0,$new_width,$new_height,$imgX,$imgY);
imagepng($dst_img, $imgPath.$imgname);
echo "<img src=\"$imgPath$imgname\"><br>";
imagedestroy($src_img);
//Wenn Bild hochgeladen, DB updaten
$uname = $_SESSION['uname'];
$nhead = $_POST['producttitle'];
$ntext = $_POST['producttext'];
conndb();
$sql = "INSERT INTO hilde (id, date, author, title, text)" .
"VALUES('', CURDATE(), '$uname', '$nhead', '$ntext', '$imgname')";
if(mysql_query($sql, $conn)) //Gespeichert
{
$saveok = "<p align=\"center\">Das Produkt wurde erfolgreich gespeichert.<br><br>".
"<a href=\"produkte.php\">Produkte</a></p>";
}
else //Error
{
echo "<p align=\"center\">ERROR! Das Produkt konnte nicht gespeichert werden.<br><br>".
"<a href=\"produkte.php\">Produkt</a></p>";
include ('ende.php');
die();
}
}
}
MySQL_Error:
Warning: move_uploaded_file(pics/upload/BILD0861.JPG) [function.move-uploaded-file]: failed to
open stream: No such file or directory in
C:\xampp\htdocs\Projekte\hildes\admin.php on line
84
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to
move 'C:\xampp\tmp\php3741.tmp' to 'pics/upload/BILD0861.JPG' in
C:\xampp\htdocs\Projekte\hildes\admin.php on line
84
Warning: getimagesize(pics/upload/BILD0861.JPG) [function.getimagesize]: failed to open stream:
No such file or directory in C:\xampp\htdocs\Projekte\hildes\admin.php on
line 85
Vielen Dank im Voraus!