i have created php function creates thumbnails , works suposed want insert thumbnail image , data in mymysqli data baze. tryed not work. not mysql , need help.
require 'config.php'; if(preg_match('/[.](jpg)$/', $filename)) { $im = imagecreatefromjpeg($path_to_image_directory . $filename); } else if (preg_match('/[.](gif)$/', $filename)) { $im = imagecreatefromgif($path_to_image_directory . $filename); } else if (preg_match('/[.](png)$/', $filename)) { $im = imagecreatefrompng($path_to_image_directory . $filename); } $ox = imagesx($im); $oy = imagesy($im); $nx = $final_width_of_image; $ny = floor($oy * ($final_width_of_image / $ox)); $nm = imagecreatetruecolor($nx, $ny); imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy); if(!file_exists($path_to_thumbs_directory)) { if(!mkdir($path_to_thumbs_directory)) { die("there problem. please try again!"); } } imagejpeg($nm, $path_to_thumbs_directory . $filename); $host = 'localhost'; $user = 'timoleon_pandess'; $pass = 'pass'; mysql_connect($host, $user, $pass); mysql_select_db('timoleon_pandessia'); $insert_path="insert `ng17p_jshopping_products`(`product_id`, `parent_id`, `product_ean`, `product_availability`, `product_template`, `product_price`, `min_price`, `different_prices`, `product_weight`, `image`) values ([value-1],[value-2],[value-3],[value-4],[value-5],[value-6],[value-7],[value-8],[value-9],[value-10])"; $var=mysql_query($inser_path); ?>
you need add variable witch contain filename of image.
$filename=$path_to_thumbs_directory.$filename;
when insert
$query="insert `ng17p_jshopping_products` (`product_id`,`parent_id`,`product_ean`, `product_availability`,`product_template`, `product_price`, `min_price`, `different_prices`, `product_weight`, `image`) values ('[value-1]','[value-2]','[value-3]','[value-4]','[value-5]','[value-6]','[value-7]','[value-8]','[value-9]','$filename')"; $res=mysql_query($query); if($res==1) { $id=mysql_insert_id; $query="select image ng17p_jshopping_products id='$id'"; $res=mysql_query($query); $row=mysql_fetch_array($res); echo 'it ok <img src="'.$row['image'].'">'; } else echo 'error';
if make done , work when try change code use mysqli, read here http://php.net/manual/ru/book.mysqli.php
Comments
Post a Comment