News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Ftp slider

Started by jhonsks, February 27, 2017, 11:50:59 PM

Previous topic - Next topic

jhonsks

Hello, my problem is that I have a slider in php but when I use it it is not shown inside the ftp, when I inspect it, the routes do not go out and I want it to show me to edit it, analyzing it is this url: the url that I leave it inside Slider

Https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css

I want it inside my ftp to be able to edit it as I said before

I'll leave the slider to see

[code]global $context;

$context['html_headers'] .= '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
  <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>';

echo $context['html_headers'];
$images = array(
       
        'http://i.imgur.com/LMRy6L5.png',
  'http://i.imgur.com/PKcMPXK.jpg',
        'http://i.imgur.com/rRWF8Hn.jpg',
       
);
$links = array(
     
  'https://www.facebook.com/',
        'https://www.google.com',
  'http://www.youtube.com/',
       
);
echo'

<div id="carousel" class="carousel slide" data-ride="carousel">
  <ol class="carousel-indicators">';
 
  for($i=0;$i<count($images);$i++)
  {
    echo'<li data-target="#carousel" data-slide-to="', $i,'" ',  $i == 0 ? 'class="active"' : '','></li>';
}
echo'
  </ol>
  <div class="carousel-inner" role="listbox">';
     
  for($i=0;$i<count($images);$i++)
  {
    echo'<div class="carousel-item ', $i == 0 ? 'active' : '','">
      <a href="',$links[$i],'" alt="First slide"><img class="d-block img-fluid" src="',$images[$i],'" alt="First slide"></a>
    </div>';
  }
   
   echo'
  </div>
  <a class="carousel-control-prev" href="#carousel" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="#carousel" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>';
[/code]

SoLoGHoST

#1
If you want images on your server, to be able to access via FTP, or whatever, you need to download those images...

So these images can be downloaded directly using file_get_contents:

        'http://i.imgur.com/LMRy6L5.png',
  'http://i.imgur.com/PKcMPXK.jpg',
        'http://i.imgur.com/rRWF8Hn.jpg',


Example:


$images = array(
       
        'http://i.imgur.com/LMRy6L5.png',
  'http://i.imgur.com/PKcMPXK.jpg',
        'http://i.imgur.com/rRWF8Hn.jpg',
       
);

$out_directory = dirname(__FILE__) . '/';
foreach($images as $image)
{
    $imagefile = file_get_contents($image);
   
    if (!empty($imagefile))
        file_put_contents($out_directory . basename($image), $imagefile);
}


The following should place those images in whatever directory you run this php script from.  Than you will need to change the urls for these images to load from that of your server, where ever you placed these images at in your server.  After which will now work via ftp, if you change the file.  If you want more files in the slider than it looks like you will need to edit the array, or you can do a glob($out_directory . "*.{jpg,png,gif}", GLOB_BRACE) to get all image files in any directory and build the $images array that way.  And than this should populate your $images array properly when you add new images to that directory via FTP or whatever, and should add those images to the slider, as well as if you remove any images from the directory via FTP (will also be removed from the slider).


Ofcourse, handling the links for those images is an entirely different story, since image data can not contain links.  This would have to be handled a different way if you need it to be dynamic.  I would recommend using the image filename as the link and just remove the extension on the filename when outputting the link.  Do not use "http://" as the start of the filename for the image (this should be prepended to the image filename in code), if you use the filename of images as links.

Just my 2 cents.

Advertisement: