// first move uploaded image
if ($_FILES['img']['tmp_name'] !== ""){
$target_path = "../images/users/" . basename($_FILES['img']['name']);
move_uploaded_file($_FILES['img']['tmp_name'], $target_path);
// Set a maximum width for the image to be resized to (in px)
$width = 200;
$file = getimagesize($target_path);
// Get new dimensions
$width_orig = $file[0];
$height_orig = $file[1];
$ratio_orig = $width_orig/$height_orig;
$height = $width/$ratio_orig;
// Resample and resize based on file extention
if($file['mime'] == "image/jpeg"){
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($target_path);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, $target_path, 100);
}
/* the stuff below was an attempt to make the image upload
file type indpendent
*/
elseif($file['mime'] == "image/png"){
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefrompng($target_path);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagepng($image_p, $target_path);
}
elseif($file['mime'] == "image/gif"){
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromgif($target_path);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagegif($image_p, $target_path);
}
$sql = "INSERT INTO table VALUES $target_path";
}
this will upload your file to the directory you specify. then you need to do an insert query on your database and insert the file path for that user. an alternative is to store the image in a BLOB field, but quite frankly i dont know how to use that method, and i prefer this method over the BLOB method anyway.
to use, name your upload field 'img'. this will name the image as the same name the image has on the users machine. you can change this in the $target_path var.
im not quite sure what you mean by "on server and localhost". ideally your localhost (is this your testing machine?) and server (remote public server?) should have the same/similar environments/setups so that running your scripts will be seamless.
i would also suggest googling file upload, and you will get tons of tutorials (some at this site too, i believe) they may be able to give you ideas about using BLOBs
hope this helps!