Jump to content


Photo

[SOLVED] what is it with pictures?


  • Please log in to reply
13 replies to this topic

#1 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 21 April 2006 - 07:36 PM

how come there is not one easy to follow gallery tutorial out there..

i been every where that googles throw me..

and only find scripts already made or tutorial made for advance ppl.

how could i get advance if i don't know the basics of workin with pictures?

every where i go is like no one cares about pictures..

dammit isn't anyone out there that knows how to deal with pictures or found a tutorial easy to follow?

pleaseee if any ones know just let me know...

please :|


thank you..

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 21 April 2006 - 08:30 PM

What do you want to know?

Ken

#3 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 21 April 2006 - 08:58 PM

[!--quoteo(post=367301:date=Apr 21 2006, 04:30 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 21 2006, 04:30 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
What do you want to know?

Ken
[/quote]


like i got this cript that i put in a index page and with subdirectories full of pictures and the scrip take the subs and make then i'm not galleries and when you click on one you see all the pictures inside..

what i meanly want to do is how do i call for pictures..

because i don't understand this one bit

define('PATH', str_replace('\\', '/', getcwd()));

thats the patht hat look for all the pictures i guess i don't know :(

#4 eves

eves
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 22 April 2006 - 03:18 PM

[!--quoteo(post=367310:date=Apr 21 2006, 03:58 PM:name=Richard181)--][div class=\'quotetop\']QUOTE(Richard181 @ Apr 21 2006, 03:58 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
like i got this cript that i put in a index page and with subdirectories full of pictures and the scrip take the subs and make then i'm not galleries and when you click on one you see all the pictures inside..

what i meanly want to do is how do i call for pictures..

because i don't understand this one bit

define('PATH', str_replace('\\', '/', getcwd()));

thats the patht hat look for all the pictures i guess i don't know :(
[/quote]


getcwd() - get current working directory function, it just returns the path of the file and replace any forward slashes with backslashes and places the value in the defined variable PATH.
eg: your file is located in say: "public_html/gallery/", this value is stored on the PATH variable and is used to display the images on other lines of code.

My guess is placing the file to where your images are will solve the problem or just change the 2nd parameter of define() to the path of your images.

Hope that helps.



#5 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 23 April 2006 - 04:04 AM

ye sho does a little, but ll the ppl that knows about php has to say is that i needed to learn OOP.. it would of really make a big different and i been trying to find a easy tutoril no wonder why i never found one..i didn't know how to wokr with OOP..

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 23 April 2006 - 05:50 AM

You don't need to learn OOP.

Ken

#7 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 23 April 2006 - 06:59 PM

[!--quoteo(post=367623:date=Apr 23 2006, 01:50 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 23 2006, 01:50 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You don't need to learn OOP.

Ken
[/quote]


well so i dont know hoe to deal with it with out learnign it, because in every tutorial about pictures they all use classes.. no one has taken the time to create a simply photo gallery with out the use of classes..

#8 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 24 April 2006 - 03:57 AM

Maybe you're looking in the wrong places?

Here is my quick & dirty tutorial on picture galleries.

Think about what you need for a gallery of pictures:
  • A directory to hold the images
  • A directory to hold the thumbnails (optional)
  • A database table to match up pictures with information about the pictures (optional)
  • A script to display the thumnails
  • A script to display a selected image (can be the same script as above)
The simplest gallery has a directory to hold the thumbnails and a directory to hold the pictures with both the thumbnail images and the fullsize images having the same name. Let's call the thumbnail directory 'thumbs' and the image directory 'images'. Both reside one level down from the directory where the script is. There is no database involved.

Below is the basic code needed to [ol type=\'1\'][*]Display the thumbnail pictures as links[*]Display a full size picture when a thumbnail is clicked.[/ol]
I haven't included how to format the display in the code. I use CSS, but some people use tables.

<?php
if(isset($_GET['pic'])) { // When a thumbnail is clicked, the name of the image files will be passed on the URL by the variable "pic"
    if (file_exists('images/' . $_GET['pic'] . '.jpg') && basename($_GET['pic'],'.jpg') == $_GET['pic'])  { // security check
       list($width, $height, $type, $attr) = getimagesize('images/' . $_GET['pic'] . '.jpg');
       echo '<img src="images/' . $_GET['pic'] . '.jpg"' . ' ' . $attr . '><br>';
    }
    echo 'Return to the <a href="' . $_SERVER['PHP_SELF'] . '">thumbnails</a>';
}
else { //display the thumbnails
    $tn = glob('thumbs/*.jpg');
    if (is_array($tn)) foreach ($tn as $pic) {
        list($width, $height, $type, $attr) = getimagesize($pic);
        echo '<a href="' . $_SERVER['PHP_SELF'] . '?pic=' . basename($pic,'.jpg') . '"><img src="' . $pic . '" ' . $attr . '></a>';
    }
}
?>

A test script using this code can be run at [a href=\"http://www.rbnsn.com/phpfreaks/gallery/test_gallery.php\" target=\"_blank\"]http://www.rbnsn.com/phpfreaks/gallery/test_gallery.php[/a]

Ken



#9 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 25 April 2006 - 03:53 AM

hmmm it works but i want to learn how to do it on my own..

i already know how to open the directory and read the file , but i don't know how to make iit display the picture

#10 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 April 2006 - 03:58 AM

This is the code that reads the directory and displays each thumbnail as a link:
<?php
//display the thumbnails
    $tn = glob('thumbs/*.jpg');
    if (is_array($tn)) foreach ($tn as $pic) {
        list($width, $height, $type, $attr) = getimagesize($pic);
        echo '<a href="' . $_SERVER['PHP_SELF'] . '?pic=' . basename($pic,'.jpg') . '"><img src="' . $pic . '" ' . $attr . '></a>';
    }?>

BTW, the [a href=\"http://www.php.net/glob\" target=\"_blank\"]glob()[/a] function makes getting lists of files from directories very easy.

Ken

#11 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 25 April 2006 - 04:31 AM

yeah but what am saying is whats the code that display the pictures.. like readdir(0 reads the directory.. what code in simple terms reads the picture, becuase you got it up there with a few arrays and i just want the code alone..

#12 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 April 2006 - 04:45 AM

I can't seperate the code from the arrays since they are all tied together.

I suggest you look at the PHP source, then show the generated pages. First show the generated code for the generated thumbnails. You should be able to see how the PHP is generating the HTML. The click on one of the thumbnails and look at the generated HTML of the displayed picture.

Also, take the script, put iin on your own server, put some debugging statements in to dump the arrays so you can see how the arrays are being used.

Ken

#13 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 25 April 2006 - 06:11 AM

for future reference it was as easy as this...


<?

$path ="/Gallery/thumbs/";
$handle = opendir($path);

while(false !==($file=readdir($handle)))
  {  if($file !="." && $file !="..")

{ echo"<img src=$path/$file>";

}
}
closerdir($handle);


?>


#14 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 25 April 2006 - 01:52 PM

As I said before, the glob() function makes this even easier:
<?php
$path ="/Gallery/thumbs/";
$files = glob($path . '*.jpg');
foreach($files as $file) {
    list($width, $height, $type, $attr) = getimagesize($file); // this function will put the "width=nnn height=nnn" into the variable $attr
    echo '<img src="' . $file . ' ' . $attr . '>';  // when ever you use the <img> tag you should specify the width and height
} ?>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users