Erratic == behavior

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Erratic == behavior

Post 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 :?
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Re: Erratic == behavior

Post by Buddha443556 »

Since your using CURLOPT_RETURNTRANSFER the result of curl_exec() is from your upload.php script maybe the error is there?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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:
Post Reply