4
我的問題是PHP的問題,我與一個朋友在圖像上傳api上工作,我們通過創建XML字符串有一個問題。圖像上傳API XML(只允許在文檔的開頭聲明)
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");
}
的問題是,如果我們連接上的XML都是好的,但如果我們上傳一個圖片,我們成爲這個error: error on line 1 at column 6: XML declaration allowed only at the start of the document
和這樣的輸出:
?<?xml version="1.0"?>
<bb-upload><error>0</error><src>http://*****.de/bb-image/data/1355858033-712.jpg</src> </bb-upload>
爲什麼是?在代碼中!
打開'<?php'標籤之前是否有輸出?也許[鬼鬼祟祟的UTF-8 BOM](http://stackoverflow.com/a/8028987/168868)? – Charles
感謝它的工作。我在HEX代碼中查找upload.php並找到它:p – Black
也許您想將此問題標記爲「已回答」。 – fbitterlich