我有一个图像上传脚本,当添加用于插入水印的功能时,它开始给出 BPOD 或 500 内部服务器错误:(
我花了整个上午试图解决这个问题,但没有结果。我知道它有很多代码,但会感谢您的帮助:
<?php
//connect
include_once('connect.php');
$storage = 'store/';
$filename = htmlentities(isset($_FILES["file"]["name"]) ? $_FILES["file"]["name"] : '', ENT_QUOTES);
$podpis = htmlentities(isset($_POST['podpis']) ? $_POST['podpis'] : '', ENT_QUOTES);
$nick = htmlentities(isset($_POST['nick']) ? $_POST['nick'] : '', ENT_QUOTES);
if(isset($_FILES['file'])) {
$errors = array();
$maxsize = 2097152;
$acceptable = array(
'image/jpeg',
'image/jpg',
'image/gif',
'image/png'
);
if(($_FILES['file']['size'] >= $maxsize) || ($_FILES["file"]["size"] == 0)) $errors[] = 'Plik za duży. Dopuszczalny max. rozmiar = 2MB. ';
if(!in_array($_FILES['file']['type'], $acceptable) && (!empty($_FILES["file"]["type"]))) $errors[] = 'Plik zabroniony. Dopuszczalne pliki: JPG, GIF i PNG. ';
if (file_exists("store/" . $filename)) {
$filename = explode(".", $filename);;
$filename = rand(1, 100) . $filename[0] . "." . $filename[1];
}
$filename = str_replace(" ", "_", $filename);
if(count($errors) !== 0) {
foreach($errors as $error) echo $error;
die();
}
if ( $_FILES['file']['type'] !== 'image/gif' ) {
move_uploaded_file($_FILES["file"]["tmp_name"], $storage . $filename);
if ( $_FILES['file']['type'] == 'image/jpeg' || $_FILES['file']['type'] == 'image/jpg' )
$im = imagecreatefromjpeg("$storage/$filename");
$stamp = imagecreatefrompng('stamp.png');
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// Output and free memory
header('Content-type: image/png');
imagepng($storage . $im);
imagedestroy($im);
$query = "INSERT INTO demoty (filename, title, nick, czas, upy) VALUES ('$im', '$podpis', '$nick', '$czas', 0)";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], $storage . $filename);
$query = "INSERT INTO demoty (filename, title, nick, czas, upy) VALUES ('$filename', '$podpis', '$nick', '$czas', 0)";
}
$czas = date('d-m-y G:H');
mysql_query($query) or die('connect error 4');
#echo '<script type="text/javascript">window.location = "index.php?page=0"</script>';
}