Jump to content

Archived

This topic is now archived and is closed to further replies.

corillo181

[SOLVED] what is it with pictures?

Recommended Posts

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..

Share this post


Link to post
Share on other sites
[!--quoteo(post=367301:date=Apr 21 2006, 04:30 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 21 2006, 04:30 PM) [snapback]367301[/snapback][/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 :(

Share this post


Link to post
Share on other sites
[!--quoteo(post=367310:date=Apr 21 2006, 03:58 PM:name=Richard181)--][div class=\'quotetop\']QUOTE(Richard181 @ Apr 21 2006, 03:58 PM) [snapback]367310[/snapback][/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.

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
[!--quoteo(post=367623:date=Apr 23 2006, 01:50 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 23 2006, 01:50 AM) [snapback]367623[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You don't [b]need[/b] 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..

Share this post


Link to post
Share on other sites
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:[list][*]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)[/list]
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.

[code]<?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>';
    }
}
?>
[/code]

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
This is the code that reads the directory and displays each thumbnail as a link:
[code]<?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>';
    }?>[/code]

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

Ken

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
for future reference it was as easy as this...


[code]<?

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

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

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

}
}
closerdir($handle);


?>[/code]

Share this post


Link to post
Share on other sites
As I said before, the glob() function makes this even easier:
[code]<?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
} ?>[/code]

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.