Page 1 of 1

Changing an array

Posted: Fri Aug 15, 2003 5:24 pm
by Pineriver
I have an image rotation script here :

Code: Select all

<?PHP 
 $DocRoot='./'; 
 
 $aPics = array(
   "url_to_file_on_server.jpg",
   "url_to_file_on_server.jpg",

   ); 
 
 
 $i = time(30) % sizeof($aPics); 
 $Filename = $aPics&#1111;$i]; 
 
 Header ('Content-type: image/jpeg'); 
 Header ('Content-Disposition: attachment; filename="pic.jpg"'); 
 readfile ($Filename); 
?>

and I am wondering it could be modified to rotate off a text file, where all the urls are kepted, also I thing the script needs editing to be able to read from remote servers. Can anyone help me ?
Thanks in advanced

Posted: Fri Aug 15, 2003 7:54 pm
by nigma
Here is some pseudocode that might help give you an idea on how to go about doing something like this?

Code: Select all

<?php
define("PICFILE", "pictureFile.txt");

if (file_exists(PICFILE))
&#123;
  if ($fp = fopen(PICFILE,  'r'))
  &#123;
    $idx = 0;
    while(!feof($fp))
    &#123;
      $picture&#1111;$idx] = fgets($fp, 1024);
      $idx++;
    &#125;

    $i = time(30) % sizeof($pictures);
    $picToUse = $pictures&#1111;$i];

    Header ('Content-type: image/jpeg');
    Header ('Content-Disposition: attachment; filename="pic.jpg"');
    readfile($picToUse);
?>