Instagram Photos array with all photos to array of selected photos [closed]

烂漫一生 提交于 2019-12-13 04:17:52

问题


I'm trying to set up my Instagram API site so that users can select photos

I am able to save the data in an database and Display the photos but not able to make photos selectable in an different array

Here's my code:

<?php
    session_start();
    require 'db.php';   
    require 'instagram.class.php';
    require 'instagram.config.php';

    if (!empty($_SESSION['userdetails']))
    {
        $data=$_SESSION['userdetails'];

        // Store user access token      
        $instagram->setAccessToken($data);

    }
    else
    {   
        header('Location: index.php');
    }

    ?>


    <?php

    $popular = $instagram->getUserMedia($data->user->id);

    // Display results
    foreach ($popular->data as $data)
    {
        echo "<img src=\"{$data->images->thumbnail->url}\";">
    }                                       
?>

回答1:


you cannot make the images "selectable" with php, you need to do that with some javascript and css styles

img.selected {
  border:solid 1px green;
}

Then with some javascript, you can find all the images with document.images or document.getElementsByTagName('img'). It would be best if you gave them all a class to select from document.getElementsByClassName('insta-photos') where the images class attribute is insta-photos

...once you have the list of images, you can add some event handling for the "selection", all you have to do is unselect all the other images (ie remove the selected class from all of the images) and select the current one by updating its css class to "selected"

Ultimately with php, you could put a link around each image that did roundtrips from the client and the server, displaying the "selected" image. you can pass it in as a url parameter..

$selected = params['selected'];

// Display results
foreach ($popular->data as $data)
{
  $css = "insta-photo"
  if ($selected == $data) { $css = "insta-photo selected" }
  echo "<a href=\"{$data->images->thumbnail->url}\" class=\"{$css}\">"
  echo "  <img src=\"{$data->images->thumbnail->url}\">"
  echo "<\a>"
}                                       


来源:https://stackoverflow.com/questions/24540724/instagram-photos-array-with-all-photos-to-array-of-selected-photos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!