Page 1 of 1

Erratic == behavior

Posted: Mon Nov 21, 2005 2:02 am
by n00b Saibot
So guys I have this function which handles upload to different servers thru CURL and handles returned errors and transfers them to my error handling framework... the real catch being an erratic behavior... Let's see the code

Code: Select all

function upload($SITE, $TempFile, $UploadPath)
{
 if($_SERVER['SERVER_NAME'] == 'media01')
  $URL = 'http://media01/ramarkz/'.($SITE=='moviez'?'moviez/upload/upload.php':'giftz/upload/upload.php');
 else
  $URL = ($SITE=='moviez'?'http://www.somesite.com/upload/upload.php':'http://www.someothersite.com/upload/upload.php');
 $ch = curl_init($URL);
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, array("path"=>$UploadPath, "file"=>"@$TempFile"));
 list($Result, $Reason) = explode("|", curl_exec($ch));
 curl_close($ch);
 $Reason = explode("~~~~~", $Reason); //explode any errors into array...
 if($Result==0) // if there was an error...
  foreach($Reason as $anErr)
   catchErr($anErr);
 return $Result==0?FALSE:TRUE;;
}
for me the code should've worked fine but the real thing being the foreach loop after if($Result==0) line executes always i.e. whether $Result is 1 or 0... :x Can anyone tell me why :?

Re: Erratic == behavior

Posted: Mon Nov 21, 2005 3:13 am
by Buddha443556
Since your using CURLOPT_RETURNTRANSFER the result of curl_exec() is from your upload.php script maybe the error is there?

Posted: Mon Nov 21, 2005 4:19 am
by n00b Saibot
yer right... i forgot to post... the error was indeed at the upload.php... put a damn '<pre>' at the start which was messing up the output and causing if statement to fail :evil: