Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

Image Upload And File Size

Recommended Posts

Hi,

I'm trying to upload rather large jpgs files (2560x1920 and ~ 2 megs in size) to my server via PHP. The problem I am having is that when I upload and attempt to resize by creating a new image, the new image is always black.

Code I'm using is:

PHP Code:

if( !empty($thefile_name) ) {                                                                                                $query = "INSERT INTO coldwell_images (imagename) VALUES ('insertimage')";                    $result = mysql_query($query) or die("Query failed");                                        $query = "SELECT LAST_INSERT_ID() as maxID FROM coldwell_images";                    $result = mysql_query($query) or die("Query failed");                    $line = mysql_fetch_array($result, MYSQL_ASSOC);                                                            $newID = $line['maxID'];                                                            if ($thefile_type == "image/gif")                        $thefile_name_new = $newID . ".gif";                    else                        $thefile_name_new = $newID . ".jpg";                                            $aNewName = "/xxx/users/u60/nbcom/public_html/images/upload/" . $thefile_name_new;                    copy($thefile,$aNewName);                                        $image_size = getImageSize($aNewName);                                        if ($thefile_type == "image/gif")                        $new_image = imageCreateFromGIF($aNewName);                    else                        $new_image = imageCreateFromJPEG($aNewName);                                        unlink($aNewName);                                         // Create large image                     if ($orientation == "horz") {                         $tmp_image = imageCreateTrueColor(385, 240);                         imagecopyresampled($tmp_image, $new_image, 0, 0, 0, 0, 385, 240, $image_size[0], $image_size[1]);                     } else {                          $tmp_image = imageCreateTrueColor(180, 240);                         imagecopyresampled($tmp_image, $new_image, 0, 0, 0, 0, 180, 240, $image_size[0], $image_size[1]);                     }                                         imagejpeg($tmp_image, $aNewName, 100);                     imageDestroy($tmp_image);                                                             $query = "UPDATE coldwell_images SET                               imagename = '$imagename'                               ,imagefilename = '$thefile_name_new'                               ,folder = '$folder'                               ,orientation = '$orientation'                               WHERE id = $newID";                                                    $result = mysql_query($query) or die("Query failed");                                         $largeImage = $thefile_name_new;                                                                                                              imageDestroy($new_image);                                                                                                                        }else{                    $errorMsg = "No File.";            }


I also have my memory limit set high ,ini_set("memory_limit","100M"), just in case it was something to do with the filesize. If I lower the filesize to ~ 1800x1300, then everything works fine.

Share this post


Link to post
Share on other sites

That's weird...I don't see anything wrong with your code...All I can think of is that the file might be too big, so the upload could be timing out, and, therefore, you get the black image. That might also explain why you can upload the smaller picture, because it wouldn't time out...Good luck!!

Share this post


Link to post
Share on other sites

Right, I dont see anything wrong with your code either. But I am not sure either if it is because of the size. You should try changing the size and see if it works out. Cheers!!! :lol:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.