I have a website that uses a CMS package and the code works just fine on a server with PHP 5.2x. When I test on PHP 5.3, thumbnails are not always generated when uploading image files.
Here's what's supposed to happen:
A user goes to a page to upload photo(s) to his gallery. He browses to his image(s) and when he uploads them, the script automatically renames the images and also creates a resized thumbnail of the original. For example, the original file will be renamed to '1.jpg' and a thumbnail will be created and it will be named '1_thumb.jpg'. Both files are located in the same directory. Now anyone visiting the gallery will see the thumbs and they can click on them and it will display the full size image.
I am not getting any errors so I am at a loss as to why this is not working on PHP 5.3. It's hit or miss. Sometimes the thumbs are generated and sometimes they are not.
The site makes use of the Smarty templating system so there are alot of pages. Below are some functions, from different pages, that I think are responsible for generating and moving the thumbs:
Will someone please look at the code and see if any of these functions work differently (or not at all) on PHP 5.3?
// RUN FILE UPLOAD FUNCTION FOR EACH SUBMITTED FILE
$update_album = 0;
$action_media = Array();
for($f=1;$f<6;$f++)
{
$fileid = "file".$f;
if($_FILES[$fileid]['name'] != "")
{
$file_result[$fileid] = $item->item_media_upload($fileid, $itemalbum_info['itemalbum_id'], $space_left);
if( !$file_result[$fileid]['is_error'] )
{
$file_result[$fileid]['message'] = 2000248;
$media_path = str_replace('./', '', $item->item_dir($item->item_info['item_id']).$file_result[$fileid]['itemmedia_id']."_thumb.jpg");
$media_link = str_replace($url->url_base, '', $url->url_create('item_media', NULL, $item->item_info['item_id'], $file_result[$fileid]['itemmedia_id']));
if( file_exists($media_path) )
{
$media_width = $misc->photo_size($media_path, "100", "100", "w");
$media_height = $misc->photo_size($media_path, "100", "100", "h");
$action_media[] = Array(
'media_link' => $media_link,
'media_path' => $media_path,
'media_width' => $media_width,
'media_height' => $media_height
);
}
$update_album = 1;
}
else
{
$file_result[$fileid]['message'] = $file_result[$fileid]['is_error'];
}
SE_Language::_preload($file_result[$fileid]['message']);
}
}
function item_photo($nophoto_image=NULL, $thumb=FALSE)
{
if( empty($this->item_info['item_photo']) )
return $nophoto_image;
$item_dir = $this->item_dir($this->item_info['item_id']);
$item_photo = $item_dir.$this->item_info['item_photo'];
if( $thumb )
{
$item_thumb = substr($item_photo, 0, strrpos($item_photo, "."))."_thumb".substr($item_photo, strrpos($item_photo, "."));
if( file_exists($item_thumb) )
return $item_thumb;
}
if( file_exists($item_photo) )
return $item_photo;
return $nophoto_image;
}
// END item_photo() METHOD
function item_photo_upload($photo_name)
{
global $database, $url;
// SET KEY VARIABLES
$file_maxsize = "4194304";
$file_exts = explode(",", str_replace(" ", "", strtolower($this->itemowner_level_info['level_item_photo_exts'])));
$file_types = explode(",", str_replace(" ", "", strtolower("image/jpeg, image/jpg, image/jpe, image/pjpeg, image/pjpg, image/x-jpeg, x-jpg, image/gif, image/x-gif, image/png, image/x-png")));
$file_maxwidth = $this->itemowner_level_info[level_item_photo_width];
$file_maxheight = $this->itemowner_level_info[level_item_photo_height];
$photo_newname = "0_".rand(1000, 9999).".jpg";
$file_dest = $this->item_dir($this->item_info[item_id]).$photo_newname;
$thumb_dest = substr($file_dest, 0, strrpos($file_dest, "."))."_thumb".substr($file_dest, strrpos($file_dest, "."));
$this->item_mkdir();
$new_photo = new se_upload();
$new_photo->new_upload($photo_name, $file_maxsize, $file_exts, $file_types, $file_maxwidth, $file_maxheight);
// UPLOAD AND RESIZE PHOTO IF NO ERROR
if( !$new_photo->is_error )
{
// DELETE OLD AVATAR IF EXISTS
$this->item_photo_delete();
// UPLOAD THUMB
$new_photo->upload_thumb($thumb_dest);
// CHECK IF IMAGE RESIZING IS AVAILABLE, OTHERWISE MOVE UPLOADED IMAGE
if( $new_photo->is_image )
$new_photo->upload_photo($file_dest);
else
$new_photo->upload_file($file_dest);
// UPDATE ITEM INFO WITH IMAGE IF STILL NO ERROR
if( !$new_photo->is_error )
{
$sql = "UPDATE se_items SET item_photo='{$photo_newname}' WHERE item_id='{$this->item_info['item_id']}'";
$resource = $database->database_query($sql);
$this->item_info['item_photo'] = $photo_newname;
}
}
$file_result = Array('is_error' => $new_photo->is_error);
return $file_result;
}
// END item_photo_upload() METHOD
// UPLOAD AND RESIZE PHOTO IF NO ERROR
if( !$new_media->is_error )
{
// INSERT ROW INTO MEDIA TABLE
$sql = "
INSERT INTO se_itemmedia
(itemmedia_itemalbum_id, itemmedia_date)
VALUES
('{$itemalbum_id}', '{$time}')
";
$resource = $database->database_query($sql);
$itemmedia_id = $database->database_insert_id();
// CHECK IF IMAGE RESIZING IS AVAILABLE, OTHERWISE MOVE UPLOADED IMAGE
$item_dir = $this->item_dir($this->item_info['item_id']);
if( $new_media->is_image )
{
$file_dest = "{$item_dir}{$itemmedia_id}.jpg";
$thumb_dest = "{$item_dir}{$itemmedia_id}_thumb.jpg";
// UPLOAD THUMB
$new_media->upload_thumb($thumb_dest, 120);
// UPLOAD PHOTO
$new_media->upload_photo($file_dest);
$file_ext = "jpg";
$file_filesize = filesize($file_dest);
}
else
{
$file_dest = "{$item_dir}{$itemmedia_id}.{$new_media->file_ext}";
$thumb_dest = "{$item_dir}{$itemmedia_id}_thumb.jpg";
if( $new_media->file_ext=='gif' )
$new_media->upload_thumb($thumb_dest, 200);
$new_media->upload_file($file_dest);
$file_ext = $new_media->file_ext;
$file_filesize = filesize($file_dest);
}
// CHECK SPACE LEFT
if( $space_left!==FALSE && $file_filesize>$space_left )
{
$new_media->is_error = 1;
$new_media->error_message = $class_item[1].$_FILES[$file_name]['name']; // TODO LANG
}
elseif( $space_left!==FALSE )
{
$space_left = $space_left-$file_filesize;
}