Hallo,
ich schreibe momentan ein Image Upload System.
Der Upload geht, aber das Script inseriert nicht in die Datenbank. Registration kann aber die Daten insarieren, es klappt jetzt nur nicht bei dem Upload.
PHP: upload.php
<?php
session_start();
function randomstring($length = 10) {
return substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 10)), 0, 5);
}
include("dbconnect.php");
$connection = mysql_select_db($mysqldatabase);
if(isset($_FILES['file']['name']) && $connection) {
$pi = pathinfo($_FILES['file']['name']);
if(strtolower($pi['extension']) == 'bmp' || strtolower($pi['extension']) == 'gif' || strtolower($pi['extension']) == 'jpg' || strtolower($pi['extension']) == 'jpeg' || strtolower($pi['extension']) == 'png' || strtolower($pi['extension']) == 'tif') {
if($_FILES['file']['size'] < 8388608) {
$filename = randomstring() . '.' . strtolower($pi['extension']);
$key = md5(md5(md5(md5(md5(base64_encode(base64_encode($filename)))))));
if(move_uploaded_file($_FILES['file']['tmp_name'], 'files/' . $filename)) {
//file_put_contents('files/' . $filename . '.key', $key);
$timestamp = time();
if(isset($_SESSION['username']))
{
$sql = "INSERT INTO `images` (`filename`, `key`, `timestamp`, `uploader`, `uploaderip`) VALUES ('" . mysql_real_escape_string($filename) . "', '" . mysql_real_escape_string($key) . "', '" . mysql_real_escape_string($timestamp) . "', '" . mysql_real_escape_string($_SESSION['username']) . "', '" . mysql_real_escape_string($_SERVER['REMOTE_ADDR']) . "');";
}
else
{
$sql = "INSERT INTO `images` (`filename`, `key`, `timestamp`, `uploader`, `uploaderip`) VALUES ('" . mysql_real_escape_string($filename) . "', '" . mysql_real_escape_string($key) . "', '" . mysql_real_escape_string($timestamp) . "', 'Kein Uploader', '" . mysql_real_escape_string($_SERVER['REMOTE_ADDR']) . "');";
}
mysql_query($sql);
header('Location: result.php?code=4&filename=' . $filename . '&key=' . $key);
exit();
} else {
header('Location: result.php?code=0');
exit();
}
} else {
header('Location: result.php?code=1');
exit();
}
} else {
header('Location: result.php?code=2');
exit();
}
} else {
header('Location: result.php?code=3');
exit();
}
?>
Alles anzeigen
Ich hoffe hier kann mit jemand helfen
Grüße,