Hi,
I'm using the following code to upload an image via form and then save it. It seems to be working OK: it saves the file with the name I assign to it, and it discerns the file type etc... the prob is when the image (jpg) is saved, it gets distorted; the colors are all jacked and it's sometimes scrambled up. Does anyone know what's causing this and how to get around it?
Thanks,
Scott Zagar
zman at dontgohere dot com
Platform: PHP 4.1.1, Apache, W2000
// code snippet:
if (is_uploaded_file($_FILES['add_img']['tmp_name'])){
$source_img = $_FILES['add_img']['tmp_name'];
$img_size = getimagesize($source_img);
// returns array 4 elements
// [0] = width
// [1] = height
// [2] = type 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order, 9 = JPC, 10 = JP2, 11 = JPX.
// [3] = text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag
if ($img_size[2] == 2){
$m_filename = $m_prod->id . ".jpg";
copy($_FILES['add_img']['tmp_name'], ".\\images\\" . $m_filename );
$msg = "Uploaded!";
} else {
$msg = "Jpegs only!";
}
} else {
$msg = "NOT UPLOADED..." . $_FILES['add_img']['tmp_name'];
}
echo $msg;
// end snippet