SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with image script

    i'm having a problem with a script i'm trying to edit.
    i downloaded an image viewing script that reads a couple dir's (image/thumbs) and makes a page out of it.
    well, i was trying to modify the script to accept a caption file as well for each pic, but it went horribly wrong.
    www.3dartisan.net/images/gallery/

    so, can someone take a look at this code and correct my undoubtedly newby mistakes.
    Code:
    <?
    $imagedir = "images"; //The image folder
    $thumbdir = "thumbs"; //The thumbnail folder
    $caption = "caption"; //The dir of the caption file
    $columns = 3; //How many images displayed per line
    
    include "header.php";
    
    ?>
    
    <table>
    
      <tr>
          <td>
          <? if ($show != "") //show the current image if any
    		{
    			print "<img src=images/$show><br>";
    			include ('caption/$file.txt');
    			print "<br>";
    		} 
    ?>
        </td>
    	</tr>
    	</table>
    	<table>
    	<tr>
          <?php 
    /*include("images.php");*/
    
    
    $i=0;
    $handle=opendir($imagedir); 
    while (false!==($file = readdir($handle))) { 
        if ($file != "." && $file != "..") { 
    	
           print "<td><a href=index.php?show=$file><img border=\"2\" src=$thumbdir/$file border=0></a><br><br>";
           include ('caption/$file.txt');
           print "<br><br></td>";
    	  ++$i;
    	  if($i == $columns) { print "</tr><tr>"; 
    	  $i = 0;
    	  }
        } 
    }
    closedir($handle); 
    
    
    ?>
      </tr>
     </table><br><br>
    </body>
    </html>
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  2. #2
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if need i can post the script without my modifications.
    that way one of you could tell me how to modify it to include a little caption file for each picture.
    Last edited by Defender1; Jun 14, 2001 at 12:14.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  3. #3
    SitePoint Zealot Overgrow's Avatar
    Join Date
    Jan 2001
    Location
    Your basement
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this...

    include ("caption/".$file.".txt");
    Overgrow the Government: The Edge Forums
    presented by Overgrow Marijuana Magazine

    *warning: adult content

  4. #4
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Warning: Failed opening 'caption/cave_chase.jpg.txt' for inclusion (include_path='.') in /usr/local/plesk/apache/vhosts/3dartisan.net/httpdocs/images/gallery/index.php on line 37
    line 37:
    Code:
    include ("caption/".$file.".txt");
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  5. #5
    SitePoint Zealot Overgrow's Avatar
    Join Date
    Jan 2001
    Location
    Your basement
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's the problem with that? It appears to be working-- you simply need to have that file, cave_chase.jpg.txt, in the proper directory and it will be included. Isn't that what you wanted to happen?

    If you want to check to see if the file exists before including, try this:

    PHP Code:
    if (file_exists("caption/".$file.".txt")) {

       include (
    "caption/".$file.".txt");


    Overgrow the Government: The Edge Forums
    presented by Overgrow Marijuana Magazine

    *warning: adult content

  6. #6
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, i managed to fix that by renaming the txt files i was using to .jpg.txt

    but i do not want to have to do this everytime i upload a new image, so is there a way to fix the fact that $file contains the name image.jpg and just image for the caption file part of the script?
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  7. #7
    SitePoint Zealot Overgrow's Avatar
    Join Date
    Jan 2001
    Location
    Your basement
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.php.net/str_replace

    $captionfile = str_replace (".jpg" , "" , $file);
    Overgrow the Government: The Edge Forums
    presented by Overgrow Marijuana Magazine

    *warning: adult content

  8. #8
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where would i put that?
    i'm still pretty new to php

    and i'm sorry if i see to be pulling this stuff out of thin air, but how would i make the script only place a certain number of image on a page, and then have next/previous page links?
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  9. #9
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and btw, i really appreciate your helping me with this.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  10. #10
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and crap, it still doesn't work when you click the image.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  11. #11
    SitePoint Zealot Overgrow's Avatar
    Join Date
    Jan 2001
    Location
    Your basement
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem.. Your final addition would look like:

    PHP Code:
    // Remove .jpg from the filename
    $captionfile str_replace (".jpg" "" $file); 

    // Before including, check to see if file exists
    if*(file_exists("caption/".$captionfile.".txt"))*{
    ***include*("caption/".$captionfile.".txt");

    Next/previous links are about 100 times trickier than what we've just gone through. I believe there was a tutorial about them either here at Sitepoint or at phpbuilder.com (another great resource).

    Here is a snatch from one of my scripts where I do some simple next/previousing. I will add some comments so you might follow along:

    PHP Code:
    // setup page numbers

    // we expect to be fed the $shownext variable as the current
    // record. If not fed, start at the beginning.

            
    if ($shownext<or empty($shownext))
                
    $shownext=1;

    // $data is the result set from our query, count the total 
    // number of images

            
    $imagecount count($data);

    // determine the first and last images to show on this page

            
    $firstnum=$shownext;
            
    $lastnum=(($firstnum+$perpage)-1);

    // if the last image to show on this page is out of range, don't 
    // go that far

            
    if($lastnum $imagecount)
                
    $lastnum=$imagecount;

    // determine what numbers would be on the previous page and 
    // what should be on the next page and form those links for 
    // later use

            
    if ($firstnum 1) {
                
    $nextlink=($firstnum-$perpage);

                if (
    $nextlink 1)
                    
    $nextlink=1;

                
    $previousurl "gallery.php?shownext=$nextlink&userid=$userid";
            }

            if (
    $imagecount $lastnum) {
                
    $nextlink=($lastnum+1);
                
    $nexturl "gallery.php?shownext=$nextlink&userid=$userid";
            } 
    Overgrow the Government: The Edge Forums
    presented by Overgrow Marijuana Magazine

    *warning: adult content

  12. #12
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, but i still don't know where i'd put that top section of code in my script.

    also, i looked at both of those sites and didn't see any tutorials on phpbuilder.com (or i'm blind)

    and sitepoint didn't have that tutorial either
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  13. #13
    SitePoint Zealot Overgrow's Avatar
    Join Date
    Jan 2001
    Location
    Your basement
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Next / Previous tutorial on phpbuilder

    Let's put the name modification at the top of your script:

    PHP Code:
    //*Remove*.jpg*from*the*filename
    $captionfile*=*str_replace*(".jpg"*,*""*,*$file); 
    In your original script, you need to make the next replacement in two places. FIND:

    PHP Code:
    include ('caption/$file.txt'); 
    replace with:

    PHP Code:
    //*Before*including,*check*to*see*if*file*exists
    if*(file_exists("caption/".$captionfile.".txt"))*{
    ***include*("caption/".$captionfile.".txt");


    If you still have problems please post the entire script again including your current modifications.
    Overgrow the Government: The Edge Forums
    presented by Overgrow Marijuana Magazine

    *warning: adult content

  14. #14
    SitePoint Addict zoordaan's Avatar
    Join Date
    Feb 2001
    Location
    NYC/Texas
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHPbuilder: Building next/previous buttons http://www.phpbuilder.com/columns/rod20000221.php3

  15. #15
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, well thx for where to put the code.

    ok, im not using a database.
    this is an image script with images in a directory, so i don't know how i'd use that for my script.

    if someone would like to share how i could put all the images, their thumbs, and captions into my database, and then adapt the image script to call/view these images i'd be well abliged.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  16. #16
    SitePoint Zealot Overgrow's Avatar
    Join Date
    Jan 2001
    Location
    Your basement
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately you're now venturing into the "I get paid to do this" category of work. Writing the script, database schema, and making sure you can install and run it sounds like a paying job to me, eh?

    If no one offers, you should start with Kevin Yank's tutorial on building a mysql/php site. That should give you the basics in order to design what you want.

    However the next / previous instructions are just as valid no matter if you are pulling from a database or pulling from a directory. I haven't done any raw file pulling/parsing except in PERL so I don't know where to point you with PHP but I suspect you can simply read in the contents of the directory:

    http://www.php.net/manual/en/ref.dir.php
    http://www.php.net/manual/en/function.opendir.php
    Overgrow the Government: The Edge Forums
    presented by Overgrow Marijuana Magazine

    *warning: adult content

  17. #17
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, i was sort of being sarcastic about that.
    i just want to know how to do it for a normal script.
    anyone know any tutorials for this sort of thing?

    back to the matter at hand:
    i've made the changes in my script, and i'm not getting any errors, but it's not showing any captions now

    www.3dartisan.net/images/gallery/index.php
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


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
  •