Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

how to replace image in file uploading and save in db

images php coding issues or problems here.

Moderators: macek, egami, gesf

how to replace image in file uploading and save in db

Postby yasirzeb » Mon May 13, 2013 3:10 am

<?php
$output = array();
$valid_formats = array("jpg", "png", "gif", "bmp", "jpeg", "JPG", "PNG");

if(!file_exists($kdzImgDir . "/kdz-uploads")){
mkdir($kdzImgDir . "/kdz-uploads");
}
$path = $kdzImgDir . "/kdz-uploads/";
$i=0;
foreach($_FILES as $data){
$name = $data['name'];
$size = $data['size'];
$tmp = $data['tmp_name'];

$image_info = getimagesize($tmp);
$width = $image_info[0];
$height = $image_info[1];

if(strlen($name)){
list($old_name, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats)){
//if($size<(1024*1024)){
$actual_image_name = time().substr(str_replace(" ", "_", $old_name), 5).$i.".".$ext;
$thumb_name = "thumb_".$actual_image_name;
if(move_uploaded_file($tmp, $path.$actual_image_name)){
$wpdb->insert("share_images",
array(
"url" => $actual_image_name,
"page_id" => $pid
),
array('%s','%s')
);
}
else $output["error"] = "move failed";
//}
//else $output["error"] = "Image file size max 1 MB";
}
else $output["error"] = "Invalid file format..";
}
else $output["error"] = "Please select image..!";
$i++;
}

?>
yasirzeb
New php-forum User
New php-forum User
 
Posts: 6
Joined: Thu Jun 21, 2012 3:18 am

Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.