Jump to content

resize pic an upload in db


neugi

Recommended Posts

Hi

i got 4 pics that i want to upload into my data base. but after is press the upload button it makes "pong" (sound) and nothing happens.

here is the code i wrote:

[code]
function bildklein($bild, $width)
    {
        $img = imagecreatefromstring($bild);

        $img_b = imagesx($img);
        $img_h = imagesy($img);

        $new_h = ($img_b / $img_h) * $width ;

        $newimg = imagecreatetruecolor($width, $new_h);

        imagecopyresized ($newimg, $img, 0, 0, 0, 0, $width, $new_h, $img_b, $img_h);
        return imagejpeg($newimg, '', 80);
    }

for ($i = 0; $i <=3; $i++) {
        if ($_FILES[bild][error][$i] == 0 )
        {
            $bildString = addslashes(fread(fopen($_FILES[bild][tmp_name][$i], "r"),$_FILES[bild][size][$i]));
            //echo $bildString;
            $bild_data = bildklein($bildString, "400");
            echo $bild_data;
            //$bildInsert = mysql_query ("INSERT INTO ref_bilder (bild) VALUES ('$bild_data')",$link);
            if ($bildInsert){
                echo 'Bild: '.$_FILES[bild][name][$i].' hochgeladen!';
            }
        }
    }
[/code]

what is wrong? maybe somebody can help me

thx
Link to comment
Share on other sites

if i remove the comments in front of the insert into the db also nothing happens. i think the problem is the bildklein function because if i remove the call of bildklein function it works but than i've got the wrong data in the database.

is there a better way to resize the pic bevore i insert it into the database?

best
Link to comment
Share on other sites

okay,

found a way that works for me:

[list]
[*]i upload the pic to a directory
[*]resize the pic and copy it to a tmp directory
[*]delete the original
[*]open the resized image and copy it to the database
[*]after insert in db was okay delete the the resized img form the tmp folder
[/list]

best
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.