PHP Codes To Upload Images

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

PHP Codes To Upload

Images
function fileUpload($file)
{
$temp = $_FILES[$file]["name"];
$newfilename1 = rand(1,99999) .$temp;
move_uploaded_file($_FILES[$file]["tmp_name"],"upload/" . $newfilename1);
"Stored in: " . "upload/" . $_FILES[$file]["name"];
$photo1="upload/" . $newfilename1;
return $photo1;
}
function thumbnailGenrator($file)
{

$original_info = getimagesize("./".$file);
$original_w = $original_info[0];
$original_h = $original_info[1];
$original_img = imagecreatefromjpeg("./".$file);
$thumb_w = 100;
$thumb_h = 100;
$thumb_img = imagecreatetruecolor($thumb_w, $thumb_h);
imagecopyresampled($thumb_img, $original_img,
0, 0,
0, 0,

$thumb_w, $thumb_h,
$original_w, $original_h);
imagejpeg($thumb_img, "thumbnail/".$file);
imagedestroy($thumb_img);
imagedestroy($original_img);
return "thumbnail/".$file;

$photo1=fileUpload("file");

$thumb=thumbnailGenrator($photo1);

$query="INSERT INTO `product_image` (`id`, `product_id`, `color_id`,


`image_path`,thumbnail_path, `default_image`) VALUES ('', '$pro_id', '$color',
'http://scountoshop.com/superadmin/$photo1','http://scountoshop.com/superadmin/
$thumb', '$default')";
mysql_query($query);

You might also like