API Image Upload API (declaration is allowed only at the beginning of the document)

My problem is the problem with PHP and XML, I work with a friend when loading the api image, and we have a problem creating an XML string.

image.php:

$simage = new SimpleImage(); $xml = new SimpleXMLElement('<bb-upload></bb-upload>'); if($key == get_key()){ require 'upload.php'; } else{ $xml->addChild('error', "102 Fehlerhafter Zugriffs Key"); } header("Content-type:text/xml;charset=utf-8"); echo $xml->asXML(); 

upload.php:

 if ($_FILES["image"]["error"] > 0) { $xml->addChild('error', "101 Bilder fehler: " . $_FILES["image"]["error"]); } else{ $data = array( 'tmp' => $_FILES["image"]["tmp_name"], 'save' => time().'-'.rand(1, 1000).'.jpg', ); $filename = $data['save']; $simage->load($data['tmp']); $simage->resize(350,300); $simage->save("../data/$filename"); $xml->addChild('error', "0"); $xml->addChild('src', "http://*******.de/bb-image/data/$filename"); } 

the problem is that we are connecting to XML, everything is fine, but if we upload the image, we will become this error: error on line 1 at column 6: XML declaration allowed only at the start of the document

and the output is as follows:

 ?<?xml version="1.0"?> <bb-upload><error>0</error><src>http://*****.de/bb-image/data/1355858033-712.jpg</src> </bb-upload> 

why? in code !!

+4
source share
1 answer

You probably have a character before the start of the XML document.

This usually causes an error.

Open the script in a hexadecimal view, this usually shows that the editor often has invisible characters. Remove them, for example. save PHP files without specification (you should always do this).

0
source

All Articles