Beste bezoekers,
op mijn site kunnen mensen plaatjes uploaden, maar als ik meerdere plaatjes achter elkaar upload, krijg ik na +- 6x een plaatje te uploaden, de volgende foutmelding:
Error:
"User "username" has already more than 'max_user_connections' active connections"
Als ik dan gewoon de hoofdpagina wil zien krijg ik dezelfde melding.
Hier de code die ik gebruik om te uploaden.
<script type="text/javascript">
function highlight(field) {
field.focus();
field.select();
}
-->
</script>
<table width="100%" border="1" cellspacing="0" bordercolor="#000000" bgcolor="#CCCCCC">
<tr>
<td width="60%" height="60" valign="top"><p>
<?php
include "includes/filter.php";
//Image Upload Script
//Created by Lappy512
//Part of ImageHostSript.
//See conf_global.php
?>
<?php
// $userfile is where the file is on the webserver
$userfile = $HTTP_POST_FILES['imagefile']['tmp_name'];
// $userfile is original file name
$userfile_name = $HTTP_POST_FILES['imagefile']['name'];
// $userfile_size is size in bytes
$userfile_size = $HTTP_POST_FILES['imagefile']['size'];
// $userfile_type is mime type e.g. image/gif
$userfile_type = $HTTP_POST_FILES['imagefile']['type'];
// $comments are the comments, but we need logic if there aren't comments.
if($_POST['comments'])
{
$comments = $_POST['comments'];
if (get_magic_quotes_gpc() == 0)
{
$comments = addslashes($comments);
}
$comments = nl2br($comments);
}
else
{
//they didn't comment
$comments = 'Geen Commentaar bij dit plaatje';
}
// $url are is the URL, but we need logic if there isn't one.
if($_POST['url'])
{
$url = $_POST['url'];
if (get_magic_quotes_gpc() == 0)
{
$url = addslashes($url);
}
$url = nl2br($url);
}
else
{
//they didn't comment
$url = 'http://www.pornholio.be';;
}
//Sporadic MIME-TYPES?
if ($userfile_type == 'image/x-png')
{
$userfile_type = 'image/png';
}
if ($userfile_type == 'image/pjpeg')
{
$userfile_type = 'image/jpeg';
}
// $userfile_error is any error encountered
$userfile_error = $HTTP_POST_FILES['imagefile']['error'];
//PHP 4.2.0+ code ONLY. This code will not work with PHP 4.1 or less
if ($userfile_error > 0)
{
echo 'Problem: ';
switch($userfile_error)
{
case 1: echo 'File exceeded Maximum upload filesize'; break;
case 2: echo 'File exceeded Maximum upload filesize'; break;
case 3: echo 'File partially uploaded'; break;
case 4: echo 'No File Uploaded'; break;
}
exit;
}
//end of code for 4.2.0+
switch($userfile_type)
{
case 'image/gif':
break;
case 'image/png':
break;
case 'image/jpeg':
break;
case 'image/bmp':
echo "BMP File format not supported. Please upload a JPEG, PNG, or a GIF. Thanks. ";
exit;
default:
echo "Problem: File is not a supported image filetype. Please upload a JPEG, PNG, or a GIF. Thanks. ";
echo "<br> your file has a MIME-TYPE of $userfile_type";
exit;
break;
}
//Lets try connecting to mySQL
@ $db = mysql_pconnect($mysql['host'], $mysql['user'], $mysql['pass']);
//IT"S NOT WORKING!
if (!$db)
{
die("error");
mysql_close();
}
mysql_select_db($mysql['db']);
//We need to get a date for our Database
$date = time();
//Put the data there!
$query = "INSERT INTO `images` ( `id` , `size` , `downloads` , `lastuse` , `type` , `comments`, `url`, `ip` , `report` ) VALUES ('', " . $userfile_size . ", '0', " . $date . ", " . '\'' . $userfile_type . '\'' . ", " . '\'' . $comments . '\'' . ", " . '\'' . $url . '\'' . ", " . '\'' . $_SERVER['REMOTE_ADDR'] . '\'' . " , '' );";
//QUERY!
$result = mysql_query($query);
if (!$result)
{
die("MySQL insert error");
mysql_close();
}
$userfile_name = mysql_insert_id();
//put the file where we want it
$upfile = './uploads/' . $userfile_name;
//need PHP 4.0.3
if(is_uploaded_file($userfile))
{
if (!move_uploaded_file($userfile, $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
mysql_close();
}
}
else
{
echo 'Problem: Possible File upload attack. Filename: '.$userfile_name;
exit;
mysql_close();
}
echo '<br>Het bestand is succesvol geupload<br/><br/>';
//get current stats
$query = "SELECT * FROM `stat_cache`";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Select error");
mysql_close();
}
$stat = mysql_fetch_array($result);
//update statistics
//files update
$files = $stat['files'] + 1;
$query = "UPDATE `stat_cache` SET files=" . $files . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
//space update
$totalspace = $stat['space'] + $userfile_size;
$query = "UPDATE `stat_cache` SET space=" . $totalspace . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
//1337 h4x0rs can resize everything, even though we can't outputz0rz to everything.
//Resample it now!
// The file
$filename = $upfile;
$thumb = './uploads/' . 'thumb_' . $userfile_name;
// Set a maximum height and width
$width = 150;
$height = 150;
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if(($width_orig < $width) && ($height_orig < $height))
{
$width = $width_orig;
$height = $height_orig;
}
else
{
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
if($userfile_type == 'image/jpeg')
{
$image = imagecreatefromjpeg($filename);
}
if($userfile_type == 'image/png')
{
$image = imagecreatefrompng($filename);
}
if($userfile_type == 'image/gif')
{
$image = imagecreatefromgif($filename);
}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
if($userfile_type == 'image/jpeg')
{
imagejpeg($image_p, $thumb);
}
if($userfile_type == 'image/png' or $userfile_type == 'image/gif')
{
imagepng($image_p, $thumb);
$userfile_type = 'image/png';
}
$userfile_size = filesize($upfile);
$id = $userfile_name;
//Put the data there!
$query = "INSERT INTO `thumbs` ( `id` , `size` , `downloads` , `lastuse` , `type` )VALUES ('$id', '$userfile_size', '0', '$date', '$userfile_type');";
//QUERY!
$result = mysql_query($query);
if (!$result)
{
die("MySQL insert error 2 " . mysql_error());
mysql_close();
}
//get current stats
$query = "SELECT * FROM `stat_cache`";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Select error");
mysql_close();
}
$stat = mysql_fetch_array($result);
//update statistics
//space update
$totalspace = $stat['space'] + $userfile_size;
$query = "UPDATE `stat_cache` SET space=" . $totalspace . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
?>
<FORM action="../nowhere" method="post" class="table_decoration">
<b><a href="<?php $siteurl; ?>">Click hier om nog een foto te uploaden</a></b><br>
<br/>HTML:<br>
<input onclick="highlight(this);" style="width: 500px;" size="80" value="<a href='<?php echo $siteurl; ?>viewer.php?id=<?php echo $id; ?>'><img src='<?php echo $siteurl; ?>thumb/<?php echo $id; ?>.jpeg'></a>">
<br/>BBCODE:<br>
<input onclick="highlight(this);" style="width: 500px;" size="80" value="[img]<?php echo $siteurl; ?>thumb/<?php echo $id; ?>.jpeg[/img]">
<br/>Thumbnail for Forums(1):<br>
<input onclick="highlight(this);" style="width: 500px;" size="80" value="[IMG]<?php echo $siteurl; ?>uploads/thumb_<?php echo $id; ?>[/IMG]">
<br/>Thumbnail for Forums(2):<br>
<input onclick="highlight(this);" style="width: 500px;" size="80" value="[img]<?php echo $siteurl; ?>uploads/thumb_<?php echo $id; ?>[/img]">
</FORM>
<br/><center>URL: <a href='<?php echo $siteurl; ?>view/<?php echo $id; ?>'><?php echo $siteurl; ?>viewer.php?id=<?php echo $id; ?></a></center>
<center><br/><img src="<?php echo $siteurl; ?>image/<?php echo $id; ?>.jpeg"></center>
<br/><center>Commentaar: <br><?php echo (stripslashes($comments)); ?>
<br>Geupload door :
<?php echo "<br/><a href=" . $url . " target=\"_blank\">" . $url . "</a><br/></center><br/>";
?>
<br><br><b><a href="<?php $siteurl; ?>">Click hier om nog een foto te uploaden</a> </b>
</center><?php mysql_close(); ?>
</p></td>
</tr>
</table>
1.618 views