Script feature problem

software development

#1

Hello all. I’ve been trying since April to get one option of a script I use on my site working to no avail. It worked before Dreamhost turned off allow_url_fopen. The section I’m having trouble with is suppose to check the image and if it doesn’t meet certain criteria then replace it with my custom replacement image. Here is the section I need help with. I’ve tried using and customizing all three option (not at the same time). Help!! My brain hurts!

$IncAlbum = 0;
switch ($AlbumImageSize) {
case ‘Small’:
$ProductImage = $Result[0][‘ImageUrlSmall’];
if (strlen(file_get_contents($ProductImage)) < 808 ) {
$ProductImage = $MissingAlbumImageSmall;
}
while (($IncAlbum) < $TotalAlbumOverrides) {
$CurrentAlbum = explode( ‘||’, $AlbumCoverOverrideList[$IncAlbum] );
if ( ($CurrentAlbum[0] == $Artist) && ( $CurrentAlbum[1] == $Album) ){
$ProductImage = $CurrentAlbum[2];
break;
}
$IncAlbum++;
}
break;
case ‘Medium’:
$ProductImage = $Result[0][‘ImageUrlMedium’];
if (strlen(file_get_contents($ProductImage)) < 808 ) {
$ProductImage = $MissingAlbumImageMedium;
}
while (($IncAlbum) < $TotalAlbumOverrides) {
$CurrentAlbum = explode( ‘||’, $AlbumCoverOverrideList[$IncAlbum] );
if ( ($CurrentAlbum[0] == $Artist) && ( $CurrentAlbum[1] == $Album) ){
$ProductImage = $CurrentAlbum[3];
break;
}
$IncAlbum++;
}
break;
case ‘Large’:
$ProductImage = $Result[0][‘ImageUrlLarge’];
if (strlen(file_get_contents($ProductImage)) < 808 ) {
$ProductImage = $MissingAlbumImageLarge;
}
while (($IncAlbum) < $TotalAlbumOverrides) {
$CurrentAlbum = explode( ‘||’, $AlbumCoverOverrideList[$IncAlbum] );
if ( ($CurrentAlbum[0] == $Artist) && ( $CurrentAlbum[1] == $Album) ){
$ProductImage = $CurrentAlbum[4];
break;
}
$IncAlbum++;
}
break;
default:
$ProductImage = $Result[0][’$ImageUrlSmall’];
if (strlen(file_get_contents($ProductImage)) < 808 ) {
$ProductImage = $MissingAlbumImageSmall;
}
while (($IncAlbum) < $TotalAlbumOverrides) {
$CurrentAlbum = explode( ‘||’, $AlbumCoverOverrideList[$IncAlbum] );
if ( ($CurrentAlbum[0] == $Artist) && ( $CurrentAlbum[1] == $Album) ){
$ProductImage = $CurrentAlbum[2];
break;
}
$IncAlbum++;
}
}

/* Alternate (unused) broken-image detection methods
// Open the product image and read the first three bytes to
// determine if the file is a GIF - Amazon uses a single pixel
GIF for items that do not have an image

$handle = fopen($ProductImage, “r”);
$contents = fread($handle, 3);
fclose($handle);
if ($contents == ‘GIF’ ){
$ProductImage = $MissingAlbumImage;
}

// Or use PHP’s GetImageSize
$ProductImageSize = getimagesize($ProductImage);
$ProductImageWidth = $ProductImageSize[0];
if ($ProductImage == ‘’ || $ProductImageWidth < 45){
$ProductImage = $MissingAlbumImage;
}
*/


#2

I am guessing that your script takes images from amazon and puts them into your own gallery/shop? If so, then yes, that’s where your problem is.

Have a look at this. http://wiki.dreamhost.com/index.php/CURL
I’m not sure if it would work with looking at image data, but it should do the trick.

Without testing replace

[quote] $handle = fopen($ProductImage, “r”);
$contents = fread($handle, 3);
fclose($handle);[/quote]
with

[quote]$ch = curl_init();
$timeout = 10; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $ProductImage);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
curl_close($ch);[/quote]


#3

What the script does is get album art for the playlist I have on my site. I use winamp (now playing) to update the playlist. It’s getting the images from amazon properly and displaying them. If it doesn’t find the album on amazon’s servers it’s suppose to use my custom “no album cover” artwork. It’s not working. That’s the problem I’m having now and what this section of the script is suppose to do. I tracked down all of the other problem with the script but this one remains.

I’ve read the the curl info on several sites and it either doesn’t apply or I don’t understand what I’m reading. Sometimes both.

I tried your suggestion but now it won’t show any images at all. I’m using the SilverSpider Play List (http://www.silverspider.com/category/silverspider-play-list/)

Thanks for the help!