Page 1 of 1

Urgent Help - How to receive a file from another server?

Posted: Wed May 17, 2006 4:03 am
by liverock
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi 

I have searched around but still can't solve my problems.

I need to receive and parse an XML file posted to me from another server.
It is non SOAP based.

here is my code:

Code: Select all

<?php
ini_set('include_path', './:../class:../../lib:./PEAR');

//
// if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
// Check if correct IP address $AllowIP <> $AllowIP

if($_SERVER['REMOTE_ADDR'] <> $_SERVER['REMOTE_ADDR'] )
	{
	echo "Your are not authorised:" . $_SERVER['REMOTE_ADDR'] . "<br>";  
	}
	else {
		  	require_once('IsterXmlSimpleXMLImpl.php');
  			include 'config.php';
  			include 'toto_variables.php';
			
			// if($_FILES['userfile']['size'] > 0)
			// if($HTTP_POST_FILES['userfile']['size'] > 0)
			if(1)
			{
			// process file
			$fileName = $HTTP_POST_FILES['userfile']['name'];
			$tmpName  = $HTTP_POST_FILES['userfile']['tmp_name'];
			$fileSize = $HTTP_POST_FILES['userfile']['size'];
			$fileType = $HTTP_POST_FILES['userfile']['type'];


			 echo "php:input";
                $input = implode("\r\n", file('php://input'));

        if (empty($doc)) {
            $doc = $input;
         }

  		echo $doc;
		
		// to create the file 
		$filename = '/home/methos2/tmp/test.txt';
$somecontent = $doc;
$handle = fopen($filename, "a+");

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

   // In our example we're opening $filename in append mode.
   // The file pointer is at the bottom of the file hence
   // that's where $somecontent will go when we fwrite() it.
   if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
   }

   // Write $somecontent to our opened file.
   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
  
   echo "Success, wrote ($somecontent) to file ($filename)";
  
    fclose($handle);

} else {
   echo "The file $filename is not writable";
}
		
		
		 
  			// read and write a document
  			$impl = new IsterXmlSimpleXMLImpl;
  			$doc  = $impl->load_file($filename);
			
			// Delete file
			unlink($filename);
			
			//$doc  = $impl->load_file($tmpName);
  			//$doc  = $impl->load_file('toto.xml');
  			// print $doc->asXML();
  			// output is the file as given above

  			// access a node's CDATA
    		$attr = $doc->RESULTS->RESULT->attributes();
			if($debug) {
					echo basename($tmpName);
					echo $HTTP_RAW_POST_DATA;
					print "Results: ";
					print $attr['draw'];
					echo "<br>";
					}
  
  			
			
		// Finally, write to database		
		include 'writedb_toto.php';		
			}
		else { 
			echo "No file posted!! "; 
				}
				
		
		}
  
  ?>

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed May 17, 2006 4:05 am
by liverock
Parsing the XML file that was received is no problem.
If I use a page with normal form for uploading the XML file using enctype="multipart/form-data", and access the file in the FILE variables, no problem.

The problem is receiving a XML file from remote server. I can't seem to access the XML file from the remote server..

HELP!!