Shaun333 Posted May 28, 2014 Share Posted May 28, 2014 Hi All, I am having an issue with my image rotating PHP function code which I have attached below. 1% of the time it can rotate through 3 of the 10 pics before stopping. 99% of the time it doesn't work at all. The issue that is popping up in the Developer console of Firefox is "[12:25:28.802] Image corrupt or truncated: http://www.mywebsite.com/wp-content/uploads/script-thumbs/79/7979_5.jpg @ http://www.mywebsite.com/wp-content/uploads/script-thumbs/79/7979_5.jpg". It is not specific to Firefox. Any assistance would be appreciated. function script_thumb($prefix,$title){ $saved_thmb = get_post_meta( get_the_ID(),'saved_thmb',true); $subPath = tubeace_sub_dir_path(get_the_ID()); $upload_dir = wp_upload_dir(); $thumb_url = $upload_dir[baseurl]."/script-thumbs/".$subPath."/"; if($saved_thmb==1){ $thumb = $thumb_url."/".get_the_ID()."_1.jpg"; } elseif($saved_thmb>1) { $def_thmb = get_post_meta( get_the_ID(),'def_thmb',true); $thumb = $thumb_url."/".get_the_ID()."_".$def_thmb.".jpg"; $rotate_thumbs = "onmouseover=\"thumbStart('$prefix-".get_the_ID()."', $saved_thmb, '$thumb_url');\" onmouseout=\"thumbStop('$prefix-".get_the_ID()."', '$thumb_url', '$def_thmb');\""; } else { return; } $thumb = "<img class=\"img-responsive\" src=\"$thumb\" $rotate_thumbs id=\"$prefix-".get_the_ID()."\" alt=\"".esc_attr($title)."\">"; return $thumb; } Cheers, Shaun Link to comment https://forums.phpfreaks.com/topic/288825-rotating-image-php-function-problem/ Share on other sites More sharing options...
QuickOldCar Posted May 28, 2014 Share Posted May 28, 2014 http://www.mywebsite.com/wp-content/uploads/script-thumbs/79/7979_5.jpg leads to http://website.1and1.com/ Link to comment https://forums.phpfreaks.com/topic/288825-rotating-image-php-function-problem/#findComment-1481113 Share on other sites More sharing options...
Shaun333 Posted May 28, 2014 Author Share Posted May 28, 2014 Sorry, I am not linking my website as it is pornographic related. I just changed the URL to that. I have checked all the thumb URLs by visiting them to see if the images appear correctly - which they do. Regards, Shaun Link to comment https://forums.phpfreaks.com/topic/288825-rotating-image-php-function-problem/#findComment-1481114 Share on other sites More sharing options...
QuickOldCar Posted May 28, 2014 Share Posted May 28, 2014 Make sure get_the_ID() is actually returning an id for each one. Before even using the thumb location...check to see if the image actually exists with file_exists() if (file_exists($thumb)) { $thumb = "<img class=\"img-responsive\" src=\"$thumb\" $rotate_thumbs id=\"$prefix-".get_the_ID()."\" alt=\"".esc_attr($title)."\">"; return $thumb; } else { return; } Link to comment https://forums.phpfreaks.com/topic/288825-rotating-image-php-function-problem/#findComment-1481122 Share on other sites More sharing options...
QuickOldCar Posted May 28, 2014 Share Posted May 28, 2014 Thinking about your firefox error tells me that the file extension may have been changed, like gd, imagemagick or whatever does it is doing it incorrectly. But a most likely cause is that the images are just way too large, try optimizing them first. Link to comment https://forums.phpfreaks.com/topic/288825-rotating-image-php-function-problem/#findComment-1481124 Share on other sites More sharing options...
Shaun333 Posted May 28, 2014 Author Share Posted May 28, 2014 Thinking about your firefox error tells me that the file extension may have been changed, like gd, imagemagick or whatever does it is doing it incorrectly. But a most likely cause is that the images are just way too large, try optimizing them first. Thanks for your replies. I will look into optimizing them. Also, are you able to assist on where I should include your code snippet within the source code I provided? Cheers, Shaun Link to comment https://forums.phpfreaks.com/topic/288825-rotating-image-php-function-problem/#findComment-1481132 Share on other sites More sharing options...
Shaun333 Posted May 28, 2014 Author Share Posted May 28, 2014 Thinking about your firefox error tells me that the file extension may have been changed, like gd, imagemagick or whatever does it is doing it incorrectly. But a most likely cause is that the images are just way too large, try optimizing them first. Btw, the strange thing is that the files do exist and when I visit the URL directly the correct thumbnail is displayed. But it comes up as "Image corrupt or truncated:" when I mouseover on the index page. It has me stumped. Could it be cycling too fast and missing the information it requires? If so, is it possible to setup my source so that it doesn't cycle to the next image until it has loaded the current one? That's all I can think of :/ Link to comment https://forums.phpfreaks.com/topic/288825-rotating-image-php-function-problem/#findComment-1481134 Share on other sites More sharing options...
QuickOldCar Posted May 28, 2014 Share Posted May 28, 2014 seeing as how you use the same $thumb variable, this looks like a good place function script_thumb($prefix,$title){ $saved_thmb = get_post_meta( get_the_ID(),'saved_thmb',true); $subPath = tubeace_sub_dir_path(get_the_ID()); $upload_dir = wp_upload_dir(); $thumb_url = $upload_dir[baseurl]."/script-thumbs/".$subPath."/"; if($saved_thmb==1){ $thumb = $thumb_url."/".get_the_ID()."_1.jpg"; } elseif($saved_thmb>1) { $def_thmb = get_post_meta( get_the_ID(),'def_thmb',true); $thumb = $thumb_url."/".get_the_ID()."_".$def_thmb.".jpg"; $rotate_thumbs = "onmouseover=\"thumbStart('$prefix-".get_the_ID()."', $saved_thmb, '$thumb_url');\" onmouseout=\"thumbStop('$prefix-".get_the_ID()."', '$thumb_url', '$def_thmb');\""; } else { return; } if (file_exists($thumb)) { $thumb = "<img class=\"img-responsive\" src=\"$thumb\" $rotate_thumbs id=\"$prefix-".get_the_ID()."\" alt=\"".esc_attr($title)."\">"; return $thumb; } else { return; } } Link to comment https://forums.phpfreaks.com/topic/288825-rotating-image-php-function-problem/#findComment-1481137 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.