SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 40
  1. #1
    ********* Articles ArticleBot's Avatar
    Join Date
    Apr 2001
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Article Discussion

    This is an article discussion thread for discussing the SitePoint article, "Build a PHP Multiple Picture Showcase Using PHP and HTML"

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    England
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As a potential way to improve the system so that you display different images to the same person on a page refres, you could track the image viewed by a user (by cookie or ip address) and then remove that from the list of images to display. That way you never show the same image to the same person twice, until they have seen them all when the list is reset.

  3. #3
    Derek Martin
    SitePoint Community Guest
    You could modify this script so that you need only provide it with a directory path, and it could then read all the .jpg/.png/.gif from that directory into an array, and proceed as above.

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    OK
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wonder, can you set a session var in the rotate.php script?
    God Bless,
    Jake

    My Blog -- www.mission36teen.com

  5. #5
    SitePoint Enthusiast mrsmiley's Avatar
    Join Date
    Jul 2004
    Location
    Melbourne
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To fix the boundary/time problem, you'd have to store the list somewhere. The biggest problem with the above method is the fact all five calls are started/completed in no particular order, potentially all happening at the same time.

    Session vars wont work unless you can somehow get the session cookie to the user's machine first up, then feed the session id through to the generator script.

    Again, because each call happens asynchronously and in no guarenteed order, you cant even say something like index=0 will be the script call that randomises the list everytime.

    If you were feeling adventurous, you could get the one script call to turn all five images in the same request, then splt them apart with some javascript, then reload them.

    Or better yet, just get a php script to return 5 random image names to a javascript array, then get the js to load the images using that url. Requires the user to have js enabled.

    Every solution has its flaws.

  6. #6
    Casper
    SitePoint Community Guest
    David, a very poor solution. Your code is bloated and won't scale.

    Why not store the product details in a database and use the database's native random functions?

    Example sql query:

    "SELECT * FROM products ORDER BY RAND()"

  7. #7
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Possibly another solution, side-stepping both the asynchronous and boundary issues:

    First, generate a list of the images in a static order (this could be cached in a file, or generated on the fly with an alphabetized directory listing).

    Then, modify the rotate.php script to uniquely divide this list of images into [em]n[/em] blocks, where n is the total number of expected calls (a variable that could be hard-coded, or passed via the query string). Select a random image from the [em]i'th[/em] block, and return it.

    This setup would guarantee random, non-repeating images from asynchronous calls. The above boundary issue would be irrelevant, as the script is free to generate the seed in any fashion. Although each image would only ever appear in one of the image slots (since the subset of images per block would be unique), this would be a trivial issue to the end-user, and would likely not be noticed (especially when the number of images increases....)

    Optionally, the list of files itself could be randomized ala cron script (this would introduce another asyncronous problem when the cron script executes, however...)

  8. #8
    Anonymous
    SitePoint Community Guest
    <?php
    // rotate images randomly but w/o dups on same page - format:
    // <img src='rotate.php?i=0'> - rotate image #0 - use 'i=1'
    // for second, etc
    // (c) 2004 David Pankhurst - use freely, but please leave in my credit
    $images=array( // list of files to rotate - add as needed
    "img1.gif",
    "img2.gif",
    "img3.gif",
    "img4.gif",
    "img5.gif" );
    $total=count($images);
    $secondsFixed=10; // seconds to keep list the same
    $seedValue=(int)(time()/$secondsFixed);
    srand($seedValue);
    for ($i=0;$i<$total;++$i) // shuffle list 'randomly'
    {
    $r=rand(0,$total-1);
    $temp =$images[$i];
    $images[$i]=$images[$r];
    $images[$r]=$temp;
    }
    $index=(int)($_GET['i']); // image index passed in
    $i=$index%$total; // make sure index always in bounds
    $file=$images[$i];
    header("Location: $file"); // and pass file reference back
    ?>


  9. #9
    Anonymous
    SitePoint Community Guest
    <?php
    // rotate images randomly but w/o dups on same page - format:
    // <img src='rotate.php?i=0'> - rotate image #0 - use 'i=1'
    // for second, etc
    // (c) 2004 David Pankhurst - use freely, but please leave in my credit
    $images=array( // list of files to rotate - add as needed
    "img1.gif",
    "img2.gif",
    "img3.gif",
    "img4.gif",
    "img5.gif" );
    $total=count($images);
    $secondsFixed=10; // seconds to keep list the same
    $seedValue=(int)(time()/$secondsFixed);
    srand($seedValue);
    for ($i=0;$i<$total;++$i) // shuffle list 'randomly'
    {
    $r=rand(0,$total-1);
    $temp =$images[$i];
    $images[$i]=$images[$r];
    $images[$r]=$temp;
    }
    $index=(int)($_GET['i']); // image index passed in
    $i=$index%$total; // make sure index always in bounds
    $file=$images[$i];
    header("Location: $file"); // and pass file reference back
    ?>



  10. #10
    Saiful_DUET
    SitePoint Community Guest
    Hi,
    I want to load and retrive images into MySQL by php. But every time failed. Pls. help me by pasting some code abouth this.

  11. #11
    aditya
    SitePoint Community Guest
    hi..how do i add all photos to the list of files if i have hundreds of images??

  12. #12
    Pierre
    SitePoint Community Guest
    @Saiful_DUET: MySQL (Databases at all) are not made for storing files or images. They are made for storing data. So, use your file system, it's even faster than a database for storing images.

  13. #13
    SitePoint Member
    Join Date
    May 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dear sir/madam,

    Please refer to this book; Database Driven Website using PHP and MySQL by Kevin Yank, pages 200-219 of chapter 10: Binary Data.
    I’d like to know how to generateindex.php. What wonders me is that when I run the page, it shows the message “successfully updated”, yet the page was hanging just like that without showing back the index.html? On the other hand, the filestore.php didn’t show anything at all as I downloading it via internet-explorer of my localhost. I want to know how to set it work as I’m trying to upload files from my own pc into the mysql-program. Yet, the filestore.php didn’t display anything even browse button to upload it(image) from my server into mysql? Does anyone can sort this out for me? What I did was just typing this url http:localhost/generateindx.php and it turns up blank? Same refers to filestores.php. while other example such as index.php were loaded accordingly correct. I already set up CREATE TABLE filestore in mysql successfully though. Still, I didn’t able to imagine how the page looks like after it is loaded as no picture of the look of this page was printed in the book. I hope next publication state an obvious and detail explanation on files upload topic.

    Email me at sufianhakim@hotmail.com

  14. #14
    SitePoint Addict eanimator's Avatar
    Join Date
    Sep 2005
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice!

  15. #15
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is a great code, but i also need each image to be hyperlinked to its own url (1.jpg to 1.html, 2.jpg to 2.html). How can i change this code to do that?

  16. #16
    Designer/Developer FarooqAzam's Avatar
    Join Date
    May 2004
    Location
    Pakistan
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great tutorial!

  17. #17
    WebMystrio
    SitePoint Community Guest
    GREAT TUT!!!!! Couldn't do it any better myself. [PS. thank you :-)]

  18. #18
    laura
    SitePoint Community Guest
    great tutorial!would be so nice if all tutorials were this user friendly!

  19. #19
    ajmd20
    SitePoint Community Guest
    it is commented, explained and IT WORKS. What more does anyone need?

  20. #20
    SitePoint Member
    Join Date
    Aug 2006
    Location
    Portsmouth, UK
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, very cool and easy to understand from a beginers point of view!

  21. #21
    Niumai
    SitePoint Community Guest
    Can't find a better tutorial. good work.

  22. #22
    Chris
    SitePoint Community Guest
    Hi, this works great in IE7 but doesn't appear to work in Firefox 2 ?

    I have also managed to combine your example with one from the AListApart website so that you no longer need the array you can just upload images into a configurable folder and it will randomly pick your images from there.

    <?php

    // rotate images randomly but w/o dups on same page - format:
    // <img src='rotate.php?i=0'> - rotate image #0 - use 'i=1'
    // for second, etc. All images selected randomly from configurable folder.
    // Chris Cowling combined
    // AUTOMATIC IMAGE ROTATOR Version 2.2 - December 4, 2003 Copyright (c) 2002-2003 Dan P. Benjamin, Automatic, Ltd.
    // and (c) 2004 David Pankhurst - use freely, but please leave in my credit


    /* ------------------------- CONFIGURATION -----------------------


    Set $folder to the full path to the location of your images.
    For example: $folder = '/user/me/example.com/images/';
    If the rotate.php file will be in the same folder as your
    images then you should leave it set to $folder = '.';

    */

    $folder = '.';


    /*

    Most users can safely ignore this part. If you're a programmer,
    keep reading, if not, you're done. Go get some coffee.

    If you'd like to enable additional image types other than
    gif, jpg, and png, add a duplicate line to the section below
    for the new image type.

    Add the new file-type, single-quoted, inside brackets.

    Add the mime-type to be sent to the browser, also single-quoted,
    after the equal sign.

    For example:

    PDF Files:

    $extList['pdf'] = 'application/pdf';

    CSS Files:

    $extList['css'] = 'text/css';

    You can even serve up random HTML files:

    $extList['html'] = 'text/html';
    $extList['htm'] = 'text/html';

    Just be sure your mime-type definition is correct!

    */

    $extList = array();
    $extList['gif'] = 'image/gif';
    $extList['jpg'] = 'image/jpeg';
    $extList['jpeg'] = 'image/jpeg';
    $extList['png'] = 'image/png';


    // You don't need to edit anything after this point.


    // --------------------- END CONFIGURATION -----------------------


    $img = null;

    if (substr($folder,-1) != '/') {
    $folder = $folder.'/';
    }

    if (isset($_GET['img'])) {
    $imageInfo = pathinfo($_GET['img']);
    if (
    isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
    file_exists( $folder.$imageInfo['basename'] )
    ) {
    $img = $folder.$imageInfo['basename'];
    }
    } else {
    $fileList = array();
    $handle = opendir($folder);
    while ( false !== ( $file = readdir($handle) ) ) {
    $file_info = pathinfo($file);
    if (
    isset( $extList[ strtolower( $file_info['extension'] ) ] )
    ) {
    $fileList[] = $file;
    }
    }
    closedir($handle);


    if (count($fileList) > 0) { //replaces $images=array("img1.gif","img2.gif","img3.gif","img1.jpg","img2.jpg" );
    $total=count($fileList);
    $secondsFixed=5; // seconds to keep list the same
    $seedValue=(int)(time()/$secondsFixed);
    srand($seedValue);
    for ($i=0;$i<$total;++$i) // shuffle list 'randomly'
    {
    $r=rand(0,$total-1);
    $temp =$fileList[$i];
    $fileList[$i]=$fileList[$r];
    $fileList[$r]=$temp;
    }
    $index=(int)($_GET['i']); // image index passed in
    $i=$index%$total; // make sure index always in bounds
    $file=$fileList[$i];
    header("Location: $file"); // and pass file reference back

    }


    }

    if ($img!=null) {
    $imageInfo = pathinfo($img);
    $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
    header ($contentType);
    readfile($img);
    }

    ?>

  23. #23
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lucasland View Post
    this is a great code, but i also need each image to be hyperlinked to its own url (1.jpg to 1.html, 2.jpg to 2.html). How can i change this code to do that?
    Great tutorial, but like lucasland, i need the images to be hyperlinked.

    Any suggestions?
    Last edited by FAM99; Oct 25, 2007 at 03:33. Reason: spelling

  24. #24
    SitePoint Zealot
    Join Date
    Oct 2007
    Location
    In the blogosphere
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'd be handling that in HTML, this only deals with rotating the image and spitting the image out.
    bLueFrogX's Blog - Random Ramblings of a NEET Techie ★

  25. #25
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Correct me if im wrong but the html output will be,

    <img src='mysite.com/rotate.php?i=1'>
    <img src='mysite.com/rotate.php?i=2'>
    <img src='mysite.com/rotate.php?i=3'>

    How does the html know which picture goes to which link without tweaking the code in php, as surely you will have to pass the correct hyperlink with the image?

    Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •