SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,738
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile does this look right? still learning

    hi all

    i have this bit of code which is selecting an img and showing on my viewphoto.php

    it works, but it just dosent look right ive seen this type before but the .jpg does not show in the address bar to view the image

    Code:
    http://mysite.com/viewphoto.php?file=images/paddy/patrick11.jpg&photo_id=11
    would it be something like

    Code:
    http://mysite.com/viewphoto.php?file=images&photo_id=11
    ????

    if that makes sense
    thanks!!!

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If the photo_id is unique for a single image, that's all you should need for the params in url:
    Code:
    http://mysite.com/viewphoto.php?photo_id=11
    The first method is not only redundant but insecure too. Anyone could change the path and access the files you do not intend to make available.

    The second method is redundand for the same reason. Although now you remove the security risk, still there's no need for multiple identification.

    Hope this helps.
    Saul

  3. #3
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,738
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes tought so, thanks php daemon!!!

    so

    Code:
    http://mysite.com/viewphoto.php?photo_id=11
    is the safe option?

  4. #4
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,738
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ive been trying to alter this but when i do the img cant be found(well just dosent show).

    PHP Code:
    echo '<td><a href ="viewphoto.php?file=images/paddy/' $row['image'] . '&photo_id='$row['photo_id'].'"> 
    <img src ="thumbs/paddy/' 
    $row['image'] . '"></a><br /><p>' $row['caption'] . '<br /><span class="orange">Views:' $row['views'] . '</span></p></td>'
    the . $row['image'] . has the patrick01.jpg in it, i deleted this

    and tryed this

    PHP Code:
    echo '<td><a href ="viewphoto.php?photo_id='$row['photo_id'].'"> 
    <img src ="thumbs/paddy/' 
    $row['image'] . '"></a><br /><p>' $row['caption'] . '<br /><span class="orange">Views:' $row['views'] . '</span></p></td>'
    which worked but didnt show the img

    any suggesstions???

    thnaks!!!!!!!

  5. #5
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Does $row['image'] really contain patrick01.jpg now when you changed the url? Post the full script, something may be in the sql query or elsewhere.
    Saul

  6. #6
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,738
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the url now:

    Code:
    http://mysite.com/viewphoto.php?photo_id=8
    $row['image'] is a field in my table where ive stored all the file names to refer to.

    thanks

    this is the viewphoto.php

    PHP Code:
    $file $_GET['file'];
    $photo_id $_GET['photo_id'];
    $update mysql_query("UPDATE photograph SET views = views+1 WHERE photo_id = '".mysql_real_escape_string($photo_id)."'") or die(mysql_error()); 
    echo 
    '<img src="'.$file.'">'
    if that helps

  7. #7
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I see. You used to use photo_id to update the views and file to display the image. Well, you should use photo_id for both, that'll make it two queries:
    PHP Code:
    $photo_id $_GET['photo_id']; 
    $update mysql_query("UPDATE photograph SET views = views+1 WHERE photo_id = '".mysql_real_escape_string($photo_id)."'") or die(mysql_error()); 
    $resource mysql_query("SELECT image FROM photograph WHERE photo_id = '".mysql_real_escape_string($photo_id)."'") or die(mysql_error()); 
    echo 
    '<img src="'.mysql_result($resource,0,"image").'">'
    Saul

  8. #8
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,738
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes thats right, but still dosent show the img on viewphoto.php

    what r the changes needed to this , i think this is the problem now.

    PHP Code:
    echo '<td><a href ="viewphoto.php?file=images/paddy/' $row['image'] . '&photo_id='$row['photo_id'].'"> 
    <img src ="thumbs/paddy/' 
    $row['image'] . '"></a><br /><p>' $row['caption'] . '<br /><span class="orange">Views:' $row['views'] . '</span></p></td>'
    thanks php daemon

  9. #9
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hm, is there an image file under thumbs/paddy/? Because if the script outputs the image file name into HTML, then the only problem is the absence of the image in the said directory.
    Saul

  10. #10
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,738
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    photodir.php is my main photo page which shows thumbs/paddy/ = all the img thumbs which have a link to viewphoto.php

    and when clicked displays viewphoto.php?photo_id=8 with the bigger img like weve been doing. if u get what i mean?

  11. #11
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    OK. Something's wrong with the query in photodir.php then. Can you post that code, please.
    Saul

  12. #12
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,738
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers! here the full code:

    PHP Code:
    require_once('includes/photo_mysql_connect.inc.php'); 

    #make the query 
    $sql 'SELECT photo_id , image, caption, views
    FROM photograph WHERE gallery = 1'
    ;
    $result = @mysql_query ($sql)or die('Error: ' mysql_error());
                     
    echo 
    '<div id="viewphoto"><h4>St. Patricks Day</h4><table><tr>'
             
    for (
    $i 0$row mysql_fetch_array ($result); $i++) 

    // close and start a new paragraph after every 4th img 
    if (intval($i 4) == ($i 4)) 
    echo 
    '</tr><tr>'

    echo 
    '<td><a href ="viewphoto.php?file=images/paddy/' $row['image'] . '&photo_id='$row['photo_id'].'"> 
    <img src ="thumbs/paddy/' 
    $row['image'] . '"></a><br /><p>' $row['caption'] . '<br /><span class="orange">Views:' $row['views'] . '</span></p></td>';
        } 
         
    echo 
    '</tr></table></div>'
    thanks!!!!!!!!!!!

  13. #13
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    So you're saying that it does not display the thumbnails? But it doesn't have to do anything with the url that you're playing with. Or am I missing something?
    Saul

  14. #14
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,738
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no, the thumbnails display ok along with the caption and viewed times, it's when i click the thumbnails which opens up the <a href ="viewphoto.php?file=images/paddy/

    thats were the images/paddy/ comes from in the address bar along with . $row['image'] which shows patrick01.jpg and so on

  15. #15
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Oh, I didn't get you right at first. And I missed something when I changed your code for viewphoto.php. Try this:
    PHP Code:
    $photo_id $_GET['photo_id']; 
    $update mysql_query("UPDATE photograph SET views = views+1 WHERE photo_id = '".mysql_real_escape_string($photo_id)."'") or die(mysql_error()); 
    $resource mysql_query("SELECT image FROM photograph WHERE photo_id = '".mysql_real_escape_string($photo_id)."'") or die(mysql_error()); 
    echo 
    '<img src="images/paddy/'.mysql_result($resource,0,"image").'">'
    Saul

  16. #16
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,738
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes that works, but it just what i had in the first place:

    Code:
    http://mysite.com/viewphoto.php?file=images/paddy/patrick08.jpg&photo_id=8
    dont we need to change this sum way?

    PHP Code:
    echo '<td><a href ="viewphoto.php?file=images/paddy/' $row['image'] . '&photo_id='$row['photo_id'].'"> 
    <img src ="thumbs/paddy/' 
    $row['image'] . '"></a><br /><p>' $row['caption'] . '<br /><span class="orange">Views:' $row['views'] . '</span></p></td>'
    thanks daemon

  17. #17
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes, remove the file part from the url and it's good:
    PHP Code:
    echo '<td><a href ="viewphoto.php?photo_id='$row['photo_id'].'"> 
    <img src ="thumbs/paddy/' 
    $row['image'] . '"></a><br /><p>' $row['caption'] . '<br /><span class="orange">Views:' $row['views'] . '</span></p></td>'
    Saul

  18. #18
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,738
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats the one!!!!!!!!! CHEERS php daemon!!!

    THANKS!

    got there in the end

  19. #19
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You're welcome.
    Saul


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
  •