Jump to content


Photo

resize pic an upload in db


  • This topic is locked This topic is locked
6 replies to this topic

#1 neugi

neugi
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 02 August 2006 - 02:27 PM

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:

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!';
            }
        }
    }

what is wrong? maybe somebody can help me

thx

#2 PHPSpirit

PHPSpirit
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 02 August 2006 - 04:26 PM


"pong"  :D


Declare your database and remove the comments ( // ).



#3 neugi

neugi
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 03 August 2006 - 06:10 AM

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

#4 manmadareddy

manmadareddy
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 03 August 2006 - 06:35 AM

I hope this kind of resize will loose the quality
It is better to use ImageMagick for resizing
the images. Its very easy process,
Just we need to execute commands through
our php code.

#5 neugi

neugi
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 03 August 2006 - 06:42 AM

and if ImageMagick is not supportet on the host ?

best

#6 manmadareddy

manmadareddy
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 03 August 2006 - 06:46 AM

just use imagefactory functions from phpclasses.org
I hope that will solve ur problem.

#7 neugi

neugi
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 03 August 2006 - 01:45 PM

okay,

found a way that works for me:

  • 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

best




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users