hallo leute,
ich brauche bitte eure hilfe.. seit einigen tagen sitz ich neben an script und bekomm schon mehr graue haare davon als Gandalf. :roll:
es ist ein fertiger script den ich nur auf meine bed. anpassen will. trozdem häng ich fest.
mein problem.... ich bekomme nur das foto gespeichert. also so wie es im script steht. alle versuche mit meinen dürftigen klassen-wissen hat nichts gepracht.
was ich brauche sind diese 4 elemente der xml. das das foto bleiben soll ist eh selbstverständlich.
<title type="text">02012010177</title> // ist der originalname des fotos
<title type="text">Hier ist der titel</title> // der titel des eintrages
<created>2010-01-04T13:41:38Z</created> // datum des eintrages ist optional, kann die DB auch machen
<content type="application/xhtml+xml" mode="xml">Hier ist der content</content> // der content des eintrages.
vielleicht hat ja einer von euch da draussen lust und laune mir zu helfen.
dankeschön fürs zuhören
unten der code...
die blog.class.php
Die Daten die ich an den Server bzw. an die Datei schicke schauen so aus...
leider sendet der client 2 x den xml header.... sehr eigenartig
also das foto wird extra mit base64 als xml versendet und der text auch extra als xml
Die Datei verarbeitet das ganze:
ich brauche bitte eure hilfe.. seit einigen tagen sitz ich neben an script und bekomm schon mehr graue haare davon als Gandalf. :roll:
es ist ein fertiger script den ich nur auf meine bed. anpassen will. trozdem häng ich fest.
mein problem.... ich bekomme nur das foto gespeichert. also so wie es im script steht. alle versuche mit meinen dürftigen klassen-wissen hat nichts gepracht.
was ich brauche sind diese 4 elemente der xml. das das foto bleiben soll ist eh selbstverständlich.
<title type="text">02012010177</title> // ist der originalname des fotos
<title type="text">Hier ist der titel</title> // der titel des eintrages
<created>2010-01-04T13:41:38Z</created> // datum des eintrages ist optional, kann die DB auch machen
<content type="application/xhtml+xml" mode="xml">Hier ist der content</content> // der content des eintrages.
vielleicht hat ja einer von euch da draussen lust und laune mir zu helfen.
dankeschön fürs zuhören
unten der code...
die blog.class.php
Code:
<?php if (version_compare(PHP_VERSION,'5','>=')) { require_once('domxml-php4-to-php5.php'); //Load the PHP5 converter } class WSSECheck { var $username; var $passworddigest; var $nonce; var $timestamp; var $input; function WSSECheck($header) { $this->input=stripslashes($header); //Note: this regex is tailored for the Nokia N95 fw20 ONLY. Different order of parameters, or timezone information are NOT HANDLED PROPERLY if (preg_match('/^UsernameToken\s+Username="([\w\d]+)"\s*,\s*PasswordDigest="([^"]+)"\s*,\s*Nonce="([^"]+)"\s*,\s*Created="(\d\d\d\d-\d\d-\d\d\w\d\d:\d\d:\d\d\w)"\s*$/',$this->input,$matches)) { $this->username=$matches[1]; $this->passworddigest=$matches[2]; $this->nonce=$matches[3]; $this->timestamp=$matches[4]; } } /* Checks the password */ function check($password) { return isset($this->passworddigest,$this->nonce,$this->timestamp) && ($this->passworddigest==(base64_encode(pack("H*", sha1(base64_decode($this->nonce) . $this->timestamp . $password))))); } } class RawBlog { var $title; var $summary; var $content; var $contentType; var $issued; function RawBlog($title,$summary,$content,$contentType,$issued) { $this->title=$title; $this->summary=$summary; $this->content=$content; $this->contentType=$contentType; $this->issued=$issued; } } class PhotoBlog extends RawBlog { function PhotoBlog($title,$summary,$content,$contentType,$issued) { parent::RawBlog($title,$summary,base64_decode($content),$contentType,$issued); } function getPhoto() { return $this->content; } } class BlogPostProcessor { var $_xml; var $_xpath; var $_entry; var $_valid=false; function BlogPostProcessor ($atomPublishXML) { $this->_xml=domxml_open_mem($atomPublishXML); if ($this->_xml) { $this->_xpath=xpath_new_context($this->_xml); $result=$this->_xpath->xpath_eval("/*[local-name()='entry']"); $this->_entry=$result->nodeset[0]; if ($this->_entry) { $this->_valid=true; } } } /** * Processes the atom publish content. Returns an blog object, depending on the content. Returns NULL if data is not valid, or not recognized. */ function process() { if ($this->isValid()) { switch ($this->getContentType()) { case 'image/jpeg': case 'image/png': $blogType='PhotoBlog'; break; default: $blogType='RawBlog'; } return new $blogType($this->getTitle(),$this->getSummary(),$this->getContent(),$this->getContentType(),$this->getIssued()); } return null; } function isValid() { return $this->_valid; } function getContent() { $result=$this->_xpath->xpath_eval("*[local-name()='content']",$this->_entry); if ($result->nodeset[0]) { return $result->nodeset[0]->get_content(); } return null; } function getContentType() { $result=$this->_xpath->xpath_eval("*[local-name()='content']/attribute::type",$this->_entry); if ($result->nodeset[0]) { return $result->nodeset[0]->get_content(); } return null; } function getTitle() { $result=$this->_xpath->xpath_eval("*[local-name()='title']",$this->_entry); if ($result->nodeset[0]) { return $result->nodeset[0]->get_content(); } return null; } function getSummary() { $result=$this->_xpath->xpath_eval("*[local-name()='summary']",$this->_entry); if ($result->nodeset[0]) { return $result->nodeset[0]->get_content(); } return null; } function getIssued() { $result=$this->_xpath->xpath_eval("*[local-name()='issued']",$this->_entry); if ($result->nodeset[0]) { return $result->nodeset[0]->get_content(); } return null; } } ?>
leider sendet der client 2 x den xml header.... sehr eigenartig
also das foto wird extra mit base64 als xml versendet und der text auch extra als xml
Code:
<?xml version="1.0" encoding="utf-8"?> <entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"> <title type="text">02012010177</title> <issued>2010-01-04T13:41:37Z</issued> <standalone xmlns="http://sixapart.com/atom/typepad#">1</standalone> <content type="image/jpeg" mode="base64">/9j/4AAQSkZJRgABAQAAAQABAAD=</content> <summary> </summary> <generator>Nokia S60 (v 10.0.020) Series60/5.0 ISF/4.3.09.34</generator> </entry> <?xml version="1.0" encoding="utf-8"?> <entry xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/"> <title type="text">Hier ist der titel</title> <created>2010-01-04T13:41:38Z</created> <content type="application/xhtml+xml" mode="xml">Hier ist der content</content> <link rel="related" type="image/jpeg" href=""/> <generator>Nokia S60 (v 10.0.020) Series60/5.0 ISF/4.3.09.34</generator> </entry>
Code:
<?php /* This code will write the received photos to the filesystem */ function logme($message) { $handle = fopen("atomdata.txt", "a"); $date = date('Y-m-d\Th:i:s\Z'); fwrite($handle, $date . ": " . $message . "\n"); fclose($handle); } require_once('blog.class.php'); function error() { header('HTTP/1.1 500 Internal server error'); //Ehm. There should be a better response code for this :) die(); } header('Content-Type: application/atom+xml;type=entry'); //Parse authenitcation header $wsse=new WSSECheck($_SERVER['HTTP_X_WSSE']); //Check username 'foo' and password 'bar' if (strtolower($wsse->username)!='foo' || !$wsse->check('bar')) { header('HTTP/1.1 401 Authorization Required'); die(); } logme($GLOBALS['HTTP_RAW_POST_DATA']); //Process the received blog entry $blogProc=new BlogPostProcessor($GLOBALS['HTTP_RAW_POST_DATA']); $blog=$blogProc->process(); if ($blog===null) { error(); } //write photo //only handle PhotoBlogs if (strtolower(get_class($blog))=='photoblog') { //Note: title and summary are not used in this example, but are available as properties in the PhotoBlog-object $file=fopen("photo_blog{$_GET['id']}.jpg",'wb'); fwrite($file,$blog->getPhoto()); fclose($file); } //All ok! header('HTTP/1.1 201 Created'); //For some reason, SOME content is required when using Apache 2.2/PHP 5.2. This was not the case using Apache 1.3/PHP 4.3: ?>
Comment