php - Resize image before saving to MySQL database -


my question similar this one i'm stuck on final bit!

the following code takes file sent html form , checks dimensions against 2 predefined values, $maxwidth , $maxheight. if it's wide, resizes image.

all want next reassign newly resized image original variable $tmpname rest of script can process it.

the following code returns these errors:

warning: fopen() expects parameter 1 string, resource given in /var/www/vhosts/galleryimaginem.com/httpdocs/img/upload.php on line 43  warning: filesize() [function.filesize]: stat failed resource id #4 in /var/www/vhosts/galleryimaginem.com/httpdocs/img/upload.php on line 44  warning: fread(): supplied argument not valid stream resource in /var/www/vhosts/galleryimaginem.com/httpdocs/img/upload.php on line 44  warning: fclose(): supplied argument not valid stream resource in /var/www/vhosts/galleryimaginem.com/httpdocs/img/upload.php on line 46 

i reckon i'm pretty close getting can help? thanks.

if (isset($_files['image']) && $_files['image']['size'] > 0) {         // temporary file name stored on server       $tmpname  = $_files['image']['tmp_name'];                list($width,$height)=getimagesize($tmpname);              if ($width>$height && $width>$maxwidth) {                 $newheight=($height/$width)*$maxwidth;                 $newwidth=$maxwidth;                 $imageresized = imagecreatetruecolor($newwidth, $newheight);                 $imagetmp     = imagecreatefromjpeg ($tmpname);                 imagecopyresampled($imageresized, $imagetmp, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);                 $tmpname=$imageresized;                  // problem lies somewhere here ^^^^             }        // read file        $fp      = fopen($tmpname, 'r');       $data = fread($fp, filesize($tmpname));       $data = addslashes($data);       fclose($fp);         // create query , insert       // our database.       $query = "insert tblprints ";       $query .= "(title,full_image) values ('img-test','$data')";       $results = mysql_query($query, $link);        // print results       print "thank you, file has been uploaded.";  } else {    print "no image selected/uploaded"; } 

lines 6-17 replace filename image data - that's meaning of

warning: fopen() expects parameter 1 string, resource given 

so in lines follow,

  // read file    $fp      = fopen($tmpname, 'r');   $data = fread($fp, filesize($tmpname));   $data = addslashes($data); 

you don't need read file. if conditional process has executed, need

$data = $tmpname // sounds strange, remember: $tmpname not name more 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -