phpFlickr photoBlog

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • phpFlickr photoBlog

    ich hab mich mal wieder an was rangwagt wo ich absolut keine Ahnung von habe, soviel gleich vorweg, also bitte nicht erschlagen!

    Ich möchte auf Basis von phpFlickr ein Photoblog erstellen das automatisch meine aktuellsten Bilder von Flcikr abholt und diese darstellt.

    Eigentlich bin ich schon erstaunt das dies soweit finktioniert, jedoch gibt es ein paar Fehler die ich alleine nicht so schnell lösen kann.

    Schaut euch das ganze doch bitte unter folgender Adresse an und gebt als Usernamen jwildefeld ein, dann kommen meine Bilder:

    http://photofeld.janwildefeld.de/

    Meine Probleme:

    1. Es wird folgende Warnmeldung ausgegeben:
    Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/u0025194115/public_html/photofeld/index.php:7) in /home/u0025194115/public_html/photofeld/phpFlickr.php on line 18

    ich weiß das es damit zu tun hat das ich vor dem php Code bereits html (den #header DIV) erzeuge. Wie kann ich das denn anders lösen!? Ich weiß nciht wie das in php geht!

    2. Ich muss im Moment immer noch meinen Usernamen in dem Formular eingeben...möchte aber das das Formular komplett weg ist und ich meinen Usernamen nur einmal im php Code angeben muss.

    Hier der Code:

    Quellcode

    1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    3. <head>
    4. <title>Photofeld - Jan Wildefelds Photoblog</title>
    5. <link rel="stylesheet" href="photofeld.css" type="text/css" media="screen,projection" />
    6. <!--[if lte IE 6]>
    7. <style type="text/css" media="screen, tv, projection">
    8. body { behavior: url(assets/js/csshover.htc); } /* hover:anything support */
    9. /* Add any IE-specific styling here */
    10. </style>
    11. <![endif]-->
    12. </head>
    13. <body>
    14. <div id="header"></div>
    15. <?php
    16. require_once("phpFlickr.php");
    17. $f = new phpFlickr("flickr id");
    18. if (!empty($_POST['username'])) {
    19. // Find the NSID of the username inputted via the form
    20. $person = $f->people_findByUsername($_POST['username']);
    21. // Get the friendly URL of the user's photos
    22. $photos_url = $f->urls_getUserPhotos($person['id']);
    23. // Get the user's first 36 public photos
    24. $photos = $f->people_getPublicPhotos($person['id'], NULL, 10);
    25. // Loop through the photos and output the html
    26. foreach ($photos['photo'] as $photo) {
    27. echo "<div id=\"outerdiv\">\n";
    28. echo "<div id=\"photodiv\">\n";
    29. echo "<a href=$photos_url$photo[id]>";
    30. echo "<img border='0' alt='$photo[title]' ".
    31. "src=" . $f->buildPhotoURL($photo, "Medium") . ">";
    32. echo "</a>";
    33. echo "</div>\n";
    34. echo "</div>\n";
    35. $i++;
    36. // If it reaches the sixth photo, insert a line break
    37. if ($i % 1 == 0) {
    38. echo "<br>\n";
    39. }
    40. }
    41. }
    42. ?>
    43. <h3>Enter a username to search for</h3>
    44. <form method='post'>
    45. <input name='username'><br>
    46. <input type='submit' value='Display Photos'>
    47. </form>
    48. </body>
    49. </html>
    Alles anzeigen
  • Fehlermeldung lautet ja so:

    Quellcode

    1. Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/u0025194115/public_html/photofeld/index.php:7) in /home/u0025194115/public_html/photofeld/phpFlickr.php on line 18


    Du siehst also dass es die phpFlickr.php ist, die den Fehler verursacht. Es reicht also nur diese Zeile nach oben zu verschieben.
    Ansonsten entfernst du einfach die if abfrage und setzt statt $_POST['username'] deinen Namen in die Funktion people_findByUsername ein.

    Habe das mal für dich gemacht:

    Quellcode

    1. <?php
    2. require_once("phpFlickr.php");
    3. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    5. <head>
    6. <title>Photofeld - Jan Wildefelds Photoblog</title>
    7. <link rel="stylesheet" href="photofeld.css" type="text/css" media="screen,projection" />
    8. <!--[if lte IE 6]>
    9. <style type="text/css" media="screen, tv, projection">
    10. body { behavior: url(assets/js/csshover.htc); } /* hover:anything support */
    11. /* Add any IE-specific styling here */
    12. </style>
    13. <![endif]-->
    14. </head>
    15. <body>
    16. <div id="header"></div>
    17. <?php
    18. $f = new phpFlickr("***FLICKRID***");
    19. $username = 'jwildefeld';
    20. // Find the NSID of the username inputted via the form
    21. $person = $f->people_findByUsername($username);
    22. // Get the friendly URL of the user's photos
    23. $photos_url = $f->urls_getUserPhotos($person['id']);
    24. // Get the user's first 36 public photos
    25. $photos = $f->people_getPublicPhotos($person['id'], NULL, 10);
    26. // Loop through the photos and output the html
    27. foreach ($photos['photo'] as $photo) {
    28. echo "<div id=\"outerdiv\">\n";
    29. echo "<div id=\"photodiv\">\n";
    30. echo "<a href=$photos_url$photo[id]>";
    31. echo "<img border='0' alt='$photo[title]' ".
    32. "src=" . $f->buildPhotoURL($photo, "Medium") . ">";
    33. echo "</a>";
    34. echo "</div>\n";
    35. echo "</div>\n";
    36. $i++;
    37. // If it reaches the sixth photo, insert a line break
    38. if ($i % 1 == 0) {
    39. echo "<br>\n";
    40. }
    41. }
    42. ?>
    43. </body>
    44. </html>
    Alles anzeigen
  • @d0nUt: Ich bin schon fast ein bisschen verlegen dich nochmal um Hilfe zu bitten, aber könntest du vielleicht doch nochmal gucken?

    Ich habe hier gesehen das man seit php5 imagefilter benutzen kann um die ausgegebenen Bilder zu manipulieren. Ich würde gerne folgenden Befehl nutzen um die Bilder auf photoFeld als schwarz/weiß Bilder darzustellen:

    imagefilter($image, IMG_FILTER_GRAYSCALE);

    Wie müsste man das in oberen Code einbauen um entsprechenden Effekt bei den Bildern zu erzielen?
  • Ah prima! Wenn ich das so mache, bekomme ich jedoch eine Fehlermeldung:

    Parse error: syntax error, unexpected '.' in /home/u0025194115/public_html/photofeld/index.php on line 36


    Daraufhin habe ich den letzten Punkt in Zeile 36 entfernt, die Fehlermeldung verschwindet, jedoch erscheint eine neue:

    Fatal error: Call to undefined function: imagefilter() in /home/u0025194115/public_html/photofeld/index.php on line 36


    Ich vermute es wäre so richtig, aber mein Webserver scheint kein php5 zu unterstützen sondern nur php4 und dort gibt es die Funktion noch nicht!? Hätte denn jemand noch einen anderen Vorschlag wie man eine Graustufenmanipulation der Bilder vornehmen könnte?!
  • Der Punkt ist in zeile 36 schon richtig. Das Semikolon davor allerdings nicht.

    Der Quellcode sollte so aussehen:



    Quellcode

    1. echo "<a href=$photos_url$photo[id]>";
    2. echo "<img border='0' alt='$photo[title]' ".
    3. "src=" . imagefilter($f->buildPhotoURL($photo, "Medium"), IMG_FILTER_GRAYSCALE); . ">";
    4. echo "</a>";


    Und anscheinend versteht dein Webserver kein php5, also entweder beim Hoster nachfragen, oder sicherlich gibt es eine PHP-Klasse die das macht...

    cya
  • Super vielen Dank...mein Hoster hat mir mitlerweile auch mitgeteilt wie ich php5 nutzen kann, ich musste einfach eine htaccess mit folgendem Inhalt anlegen

    AddType application/x-httpd-php5 .php

    Dann habe ich den Code eingefügt und ausprobiert, ledier erschien wiederum eine Fehlermeldung:

    Warning: imagefilter() expects parameter 1 to be resource, string given in /home/u0025194115/public_html/photofeld/index.php on line 36

    Warning: Wrong parameter count for imagefilter() in /home/u0025194115/public_html/photofeld/index.php on line 36
    [/quote]
  • Nanu, hattet ihr es heute eilig? imagefilter als boolean im src attribut? :)

    @topic: Problem ist, dass diese image Funktionen nur auf interne Bilder angewendet werden können. Da flickr aber extern ist, muss man sich mit file_get_contents und createimagefromstring behelfen.

    Hier meine Lösung:
    echo "<img border='0' alt='$photo[title]' ".
    "src=grey.php?url=" . $f->buildPhotoURL($photo, "Medium") . ">";
    echo "</a>";

    grey.php

    Quellcode

    1. <?php
    2. $cache = 'cache/'; //Ordner mit Schreibrechten erstellen
    3. $path = urldecode($_GET['url']);
    4. //security reasons
    5. $host = parse_url($_GET['url']);
    6. $host = $host['host'];
    7. if(substr($host, -10) == 'flickr.com') {
    8. header('Content-type: image/jpg');
    9. $file = 'cache/'.md5($path);
    10. if(is_file($file)) { //cache vorhanden
    11. readfile($file);
    12. } else {
    13. $data = file_get_contents($path);
    14. $im = @imagecreatefromstring($data);
    15. if ($im && imagefilter($im, IMG_FILTER_GRAYSCALE)) {
    16. touch($file);
    17. imagepng($im, $file); //cache erstellen
    18. imagepng($im);
    19. imagedestroy($im);
    20. }
    21. }
    22. } else die('hacking attempt');
    23. ?>
    Alles anzeigen
  • Super das funktioniert...allerdings wird die ganze Sache dadurch extrem viel langsamer, oder habe ich beim erstellen des Cacheordners etwas falasch gemacht und es liegt daran?!

    Habe einfach einen Ordner "Cache" im Huaptverzeichnis, wo auch alle anderen dateien liegen, erstellt und diesem die Rechte 775 gegeben...müsste doch passen.

    Wäre eine Lösung mit JavaScript wohl schneller?

    PS: Ich korrigiere mich, habe gerade nochmal den BrowserCache gelöscht etc. und es ging beim Laden viel schneller als zuvor...super danke nochmal!
  • Ich möchte nun andere andere Variante auf die Beine stellen...soweit paßt auhc schon alles. Diesmal sollen die aktuellsten 9 Bilder von Flickr geholt werden und in einer 3 x 3 Matrix dargestellt werden.

    Hier soweit der Code
    // Loop through the photos and output the html
    foreach ($photos['photo'] as $photo) {
    echo "<a href=$photos_url$photo[id]>";
    echo "<img border='0' alt='$photo[title]' ".
    "src=grey.php?url=" . $f->buildPhotoURL($photo, "Small") . ">";
    echo "</a>";
    $i++;
    // If it reaches the sixth photo, insert a line break
    if ($i % 3 == 0) {
    echo "<br>\n";
    }


    Jetzt möchte ich zu jedem Bild eine automatisch generierte Reflexion nach diesem Vorbild zufügen: reflection.corephp.co.uk/, das klappt aber noch nicht so ganz. Mit einer Java Variante hat es schon funktioniert, nur zerhaut es mir dann die 3x3 Matrix und alles wird untereinander dargestellt.
  • Hi,

    erstmal musst du nachdem du einen Zeilenumbruch gemacht hast, i wieder auf 0 setzen (vor der Schleife zur Sauberkeit auch), damit er wiederum nach 3 Bildern einen Bruch macht.

    Probier das erstmal, dann sehen wir weiter...

    Und beschreib mal dein "zerhaut" näher...

    Quellcode

    1. $i = 0;
    2. // Loop through the photos and output the html
    3. foreach ($photos['photo'] as $photo) {
    4. echo "<a href=$photos_url$photo[id]>";
    5. echo "<img border='0' alt='$photo[title]' ".
    6. "src=grey.php?url=" . $f->buildPhotoURL($photo, "Small") . ">";
    7. echo "</a>";
    8. $i++;
    9. // If it reaches the sixth photo, insert a line break
    10. if ($i % 3 == 0) {
    11. echo "<br>\n";
    12. $i = 0;
    13. }
    Alles anzeigen


    viel Spaß ;)

    cya
  • So, sorry mein Akku ist in der Uni alle gegangen und ich hatte ausnahmnsweise mein Ladegerät nicht dabei.

    Ich wollte meiner vorherigen Antwort eigentlich noch folgendes hinzufügen

    Unter http://www.janwildefeld.de/photofeld habe ich einmal folgendes ausrobiert:

    Quellcode

    1. // Loop through the photos and output the html
    2. foreach ($photos['photo'] as $photo) {
    3. echo "<a href=$photos_url$photo[id]>";
    4. echo "<img border='0' alt='$photo[title]' ".
    5. "src=grey.php?url=" . $f->buildPhotoURL($photo, "Small") . ">";
    6. echo "<br>\n";
    7. echo "<img border='0' alt='Reflection' ".
    8. "src=reflect.php?url=" . $f->buildPhotoURL($photo, "Small") . ">";
    9. echo "</a>";
    10. $i++;
    11. // If it reaches the sixth photo, insert a line break
    12. if ($i % 3 == 0) {
    13. echo "<br>\n";
    14. }
    15. }
    Alles anzeigen


    Das funktioniert wie man sehen kann allerdings noch nicht wirklich...und da wollte ich hier mal wieder um Lösungvorschläge betteln :-p
  • Wenn du wirklich einen 3x3 Block nutzen würdest, würde dein Code funktionieren.
    Aber du zeigst überall 2 Bilder an und fügst dazwischen auch noch Zeilenumbrüche ein.

    Probiers mal mit einer Tabelle.

    Quellcode

    1. echo '<table border="1">';
    2. // Loop through the photos and output the html
    3. foreach ($photos['photo'] as $photo) {
    4. if ($i % 3 == 0) {
    5. echo "<tr>\n";
    6. }
    7. echo "<td><a href=$photos_url$photo[id]>";
    8. echo "<img border='0' alt='$photo[title]' ".
    9. "src=grey.php?url=" . $f->buildPhotoURL($photo, "Small") . ">";
    10. echo "<br>\n";
    11. echo "<img border='0' alt='Reflection' ".
    12. "src=reflect.php?url=" . $f->buildPhotoURL($photo, "Small") . ">";
    13. echo "</a></td>";
    14. $i++;
    15. // If it reaches the sixth photo, insert a line break
    16. if ($i % 3 == 0) {
    17. echo "<tr>\n";
    18. }
    19. }
    20. echo "</table>";
    Alles anzeigen
  • Ah ja verstehe, o.k. ich werde mal versuchen ob ich das auch mit einer Liste und CSS hinbekomme und als neue Zeile dan einfach nach drei Bildern ein Absatz <p> einfüge, müsste eigenltich klappen.

    Was allerdings immer noch nicht funktioniert sind die php image Reflections!? Irgendwie hab ich da noch einen Fehler drin? Kommt er mit den Flickr Bildern nicht zurecht?!
  • So ich hab es nun per JavaScript gelöst...für IE hab ich noch nichts optimiert, also nicht wundern wenn einer mit IE surft und nichts paßt.

    Ich hätte nun noch eine Idee und würde die Bilder gerne bei anklicken in einer anderen größe öffnen, anstatt das man zu flcikr geleitet wird.

    Hierzu benötige ich erneut Hilfe wie ich "<a href=" angeben muss?

    Dies ist der aktuelle Code:

    Quellcode

    1. echo "<ul>";
    2. // Loop through the photos and output the html
    3. foreach ($photos['photo'] as $photo) {
    4. if ($i % 3 == 0) {
    5. echo "<p>\n";
    6. }
    7. echo "<li class=\"bilderblock\"><a href=$photos_url$photo[id]>";
    8. echo "<img border='0' class=\"reflect rheight40 ropacity30\" alt='$photo[title]' ".
    9. "src=grey.php?url=" . $f->buildPhotoURL($photo, "Small") . ">";
    10. echo "</a></li>";
    11. $i++;
    12. // If it reaches the sixth photo, insert a line break
    13. if ($i % 3 == 0) {
    14. echo "<p>\n";
    15. }
    16. }
    17. echo "</ul>";
    Alles anzeigen


    Mir schwebt etwas in dieser Art vor

    Quellcode

    1. echo "<li class=\"bilderblock\"><a href=$f->buildPhotoURL($photo, "Medium")>";


    würde das so funktionieren?
  • ja, damit kommst du DIREKT auf das bild. Ohne flickr.com außenrum.
    Vermutlich willst du aber das große bild auch auf deiner Seite einbauen.
    Dazu verlinkst du deine index.php mit der url als parameter

    z.B. index.php?e=$f->buildPhotoURL($photo, "Medium")

    und auf deiner index musst du die dann abfragen

    Quellcode

    1. if(isset($_GET['e'])) {
    2. echo '<img src="'. $_GET['e'].'" alt="" />';
    3. } else {
    4. echo show_uebersicht();
    5. }