Php :: Image uploading not working. Help please

software development

#1

Hi

I’ve used a php script for image uploading several times with my previous host (powweb). Now I’m trying the same script with DH. Unfortunately, it’s not working … very weird as I can see that the image name, image type, image size, image height, image height, all the fields are getting inserted in the database properly (image data I can’t check as it’s blob), but the image is still not getting displayed.

Basically there are two files that’s doing the work. One file holding a script to upload image, and the other file to fetch image for displaying. I have tried to upload image directly thro’ the phpmyadmin, and that works. it shows that the file that fetches image from the database to display in the web, is working perfectly.

I am wondering if I am doing any mistake myself uploading the image … here is the script that I’m using for this work. Can anyone check and tell me why it’s not working? Or may be there’s some DH related issue that I don’t know.

[quote]if (is_uploaded_file($_FILES[‘auth_img’][‘tmp_name’])) {
$allowed_types = array(“image/jpg”, “image/jpeg”, “image/pjpeg”, “image/png”, “image/x-png”);
$uploadfile=$_FILES[‘auth_img’][‘tmp_name’];
$uploadname=$_FILES[‘auth_img’][‘name’];
$uploadtype=$_FILES[‘auth_img’][‘type’];
if(!in_array($uploadtype, $allowed_types)) {
print ’


At the moment we are accepting jpg and png images only (Format jpg, jpeg, png).


Please GO BACK and submit an image with the proper format.
’; exit;
}
////////////////////////////////////////////////////////////
// RESIZE IMAGE TO BETTER DIMENSIONS AND SIZE
$src = ImageCreateFromString(file_get_contents($uploadfile)); // bitmap image works with all image types
$new_width = 140; // set max limit for width for new image
$new_height = 140; // set max limit for height for new image
$old_width = ImageSx($src); //find width of old file
$old_height = ImageSy($src); //find height of old file
if (($old_height > $new_height) || ($old_width > $new_width)) {
if ($old_height > $old_width)
{ $new_width = round(($new_height / $old_height) * $old_width); }
if ($old_width > $old_height)
{ $new_height = round(($new_width / $old_width) * $old_height); }
} else
{ $new_width = $old_width;
$new_height = $old_height;
}
$dst = ImageCreateTrueColor($new_width,$new_height); //create new image
ImageCopyResampled($dst, $src,0,0,0,0,$new_width,$new_height,$old_width,$old_height); // copy old image into new image resized
Imagedestroy($src);
$quality = 75 ; //new file quality scale 0-100 (100 best)
ob_start();
if ($uploadtype==image/png)
{Imagepng($dst, $uploadfile);} else {
Imagejpeg($dst, ‘’, $quality); }
$filedata = ob_get_clean();
Imagedestroy($dst);
/////////////////////////////////////////////////////////////
$uploadsize = strlen($filedata);
$img_height=$new_height;
$img_width=$new_width;

//prepare for database insert by adding backslashes before special characters
$filedata=addslashes($filedata);

$photo = “UPDATE $image_base SET
img_name=’$uploadname’,
img_data=’$filedata’,
img_type=’$uploadtype’,
img_size=’$uploadsize’,
img_height=’$img_height’,
img_width=’$img_width’
WHERE check_data=’$check_data’”;

if(!@mysql_query($photo)) {die(‘

Error updating the image. Error: ‘. mysql_error() .’

’);}
}[/quote]
Thanks a lot guys.

Web’s ultimate debate center - www.SharpDebate.com


#2

Solved. :slight_smile:

Web’s ultimate debate center - www.SharpDebate.com


#3

what was the fix?
I also am having some issues.