Forum Moderators: coopster
However, one of the pieces of code written by another programmer is simply baffling me at the moment, and I think it may be due to the fact the code was badly written for a much older version of PHP compared to the version the site is on now with my new host etc
The code should be searching for images from one of my suppliers websites but it runs and does nothing at all...I have checked the suppliers URL's and they match the code so what is going on here....am I missing something really simple?
A sample URL is as follows:-
so the URL constant is always http://www.example.com/prod_images/
and the code from my site is below :-
<?php I then use the following code to upload the files onto my own site :- I would appreciate any advice from anyone with greater experience as I have spent around a week trying to get this code to function without any success! [1][edited by: eelixduppy at 7:20 pm (utc) on July 12, 2007]
$play=time();
include "connection.php";
$id=(isset($_REQUEST[id]))?$_REQUEST[id]:0;
$resource=mysql_query("SELECT * FROM `gadgets_product` WHERE `OriginalUrl`!= '' AND `id`>'$id';");
for($i=0;$i<mysql_num_rows($resource);$i++){
$array=mysql_fetch_array($resource);
$id=$array['id'];
$field=$array['OriginalUrl'];
if(time()-$play>20)break;
$htm=str_replace("!","-",str_replace("'","-",str_replace("®","-",str_replace("/","-",str_replace("\"","-",str_replace(" ","-",$field))))));
$img=file_get_contents("http://www.example.com/prod_images/".$htm.".htm.");
$startsrc=strpos($img,"<td width=\"75\"><div align=\"left\"><img src=\"",0);
$startsrc+=43;
$endsrc=strpos($img,"\"",$startsrc);
$src=substr($img,$startsrc,$endsrc-$startsrc);
$srco=explode("thumbs/150/thumb_",$src);
$srco=$srco[0].$srco;
mysql_query("UPDATE `gadgets_product` SET `ico_file` = '$src' , `image_file` = '$srco' , `OriginalUrl` = '' WHERE `id` = '$id'");
header("Location:imageupload.php?id=$id");
}header("Location:imagecopy.php");
?>
<?php
$play=time();
include "connection.php";
$id=(isset($_REQUEST[id]))?$_REQUEST[id]:0;
$resource=mysql_query("SELECT * FROM `gadgets_product` WHERE `image_file` LIKE 'http:%' AND `id` >= '$id';");
$rows=mysql_num_rows($resource);
for($k=0;$k<$rows;$k++){
$array=mysql_fetch_array($resource);
$id=$array['id'];
$htm=$array['image_file'];
if(time()-$play>20)header("Location:imagecopy.php?id=$id");
$ext=".jpg";
$recurso = @imagecreatefromjpeg($htm);
if(!$recurso){
$ext=".gif";
$recurso = @imagecreatefromgif($htm);
}
if($recurso){
$arreglo=getimagesize($htm);
for($i=0;$i<2;$i++){
if($i==0){
$pathdestino="products/".$id.$ext;
$ancho=180;
$alto=180;
}else{
$pathdestino="products/".$id.$ext;
$ancho=280;
$alto=280;
}
$relacionalto=$alto/$arreglo[1];
$relacionancho=$ancho/$arreglo[0];
if($relacionalto<$relacionancho)$ancho=$arreglo[0]*$relacionalto;
else $alto=$arreglo[1]*$relacionancho;
if($ancho>$arreglo[0]¦¦$alto>$arreglo[1]){
$ancho=$arreglo[0];
$alto=$arreglo[1];
}
$nueva=imagecreatetruecolor($ancho,$alto);
imagecopyresampled($nueva,$recurso,0,0,0,0,$ancho,$alto,$arreglo[0],$arreglo[1]);
imagejpeg($nueva,$pathdestino,100);
}
}
mysql_query("UPDATE `gadgets_product` SET `ico_file` = '".$id.$ext."' , `image_file` = '".$id."_full".$ext."' WHERE `id` = '$id'");
header("Location:imagecopy.php?id=$id");
}
?>
Nick
[edit reason] example.com [/edit]
You say you are getting errors? Could you please share them and their respective lines with us, please?