Changing an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Pineriver
Forum Commoner
Posts: 50
Joined: Fri Aug 15, 2003 5:24 pm

Changing an array

Post 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
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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);
?>
Post Reply