1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Temporarily Rename Image File (jpg/gif)?

Discussion in 'PHP' started by kkibak, Mar 19, 2007.

  1. #1
    Hi,

    I wrote a script for a game where you need to identify what is pictured in a random image (you are presented with multiple choice options).

    I managed to make it pretty tough to cheat, but one problem remains: some of the images have the answer as their file names. For example if there were a pic of brittany spears, the file name on our server might be brit-spears.jpg.

    I know this shouldn't be too tough, but I'm having trouble figuring out how I can temporarily rename the image as something random so the user can't cheat by viewing source. Any code or links to code that can do this would be much appreciated. Some of the pics are gif and some jpeg, so I'm going to need to write something capable of handling both.

    Thanks
     
    kkibak, Mar 19, 2007 IP
  2. Wyla

    Wyla Well-Known Member

    Messages:
    924
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    140
  3. jwalsh

    jwalsh Peon

    Messages:
    8
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I would build a lookup in a table that maps a random string to the real filename. Then show the random filename.
     
    jwalsh, Mar 19, 2007 IP
    kkibak likes this.
  4. kkibak

    kkibak Peon

    Messages:
    1,083
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #4
    THanks for the replies. Will check the link in a minute, but for jwalsh: forgive my ignorance but how would i map a random string to the real file name and have the code you see when clicking view > source not show the true file name?
     
    kkibak, Mar 19, 2007 IP
  5. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #5
    In your database, you should have a unique ID for each row. If you also store the filename of the image in that table, you can lookup the ID to find the filename. For example, in your HTML you would put the image src as "image.php?id=5". The image.php script will lookup the corresponding real filename using WHERE id=5 for your database and output that image - you can do that with a content-type header and a readfile().
     
    rodney88, Mar 20, 2007 IP
    kkibak likes this.
  6. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <img src="get_data.php" alt="strip" width="326" height="202">

    in get_data.php

    Read contents for image file(fopen,fread,....) and print the contents.
     
    jitesh, Mar 20, 2007 IP
    kkibak likes this.
  7. kkibak

    kkibak Peon

    Messages:
    1,083
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Awesome, trying this now. Thanks again guys for the replies, gotta love DP.

    EDIT: Got it working. I ended up using the get_data.php concept with a variable like get_data.php?rand=1049925 and then within get_data.php I simply have header("Location: $photoURL");


    As far as I can tell this is working perfectly..
     
    kkibak, Mar 20, 2007 IP
  8. jwalsh

    jwalsh Peon

    Messages:
    8
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Exactly, except we usually add a unique string separate from the ID. It's not necessary in this case though.
     
    jwalsh, Mar 20, 2007 IP
  9. pangea

    pangea Guest

    Messages:
    557
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #9
    could you link to an image that doesnt exist, then use .htaccess to forward to the new image? then block the .htaccess file?

    just an idea
     
    pangea, Mar 20, 2007 IP
  10. kkibak

    kkibak Peon

    Messages:
    1,083
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #10
    That's actually a really good question I'd be interested in hearing the answer to (or maybe I should not be lazy and just go test it)...
     
    kkibak, Mar 21, 2007 IP