PHP水印脚本 - 返回500内部服务器错误

时间:2012-12-18 11:52:51

标签: php image-processing watermark internal-server-error

我有一个图片上传脚本,当添加插入水印的功能时,它开始提供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>';

}

0 个答案:

没有答案