00:00
00:00
Newgrounds Background Image Theme

SpeakyDooman just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

PHP : Easy gallery

2,797 Views | 8 Replies
New Topic Respond to this Topic

PHP : Easy gallery 2006-08-01 13:40:05


PHP : Main
I already made that tutorial 2 weeks ago in french and I decided to translate it :)

So, did you ever want to create a gallery on your site, but you don't want to create a page for each image? Here's the solution!!

I will take as example an image gallery , but you could use this code for anything (videos, flash, etc)

1. First of all, upload your images with simple names (ex: gallery1, gallery2, etc…)

2. Create a page where you will put the links to your different images.

3. Create a new page with the *.php file type.

4. Now I will explain you the codeyou have to put!

First, the code:

<img src= "
<?
$src = $_GET [“image”]
echo $src
? >
“/>

Now let us analyze the code!

<img src= "

Quite obvious, the code to put an image (only the beginning)

<?

Opens the PHP code.

$src = $_GET [“image”]

Defined the variable “src”. In your URL, you will have to put, afterthe name of page (ex: image.php), this: ”? image=name of the image.jpg " The $_GET function will seek in the URL the value of “image” (defined in the URL with”? image=URL ") Then, if my image has the name “image1.jpg”, the URL would have to look like that:

www.mysite.com/image.php?image=image1.jpg.

echo $src

Usse the ECHO function to write the URL of your image (image1.jpg).

A principle that it is necessary to understand in PHP is that all the code is executed on the host's computer and is sent has the user in plain HTML.

? >

Closes the PHP code

“/>

Closes the image code

Then, the output of this code would be, after execution on the host's computer:

<img src= " image1.jpg "/>

A very simple code which saves you hours (minutes?) of work!

Obviously you can replace the code outside of the PHP by anything you want, I just explained the basics!


-Disregard females (fuck bitches)

-Acquire currency (get money)

-Ignite cannabis frequently (smoke sum with your homies)

BBS Signature

Response to PHP : Easy gallery 2006-08-01 16:48:41


This is a very simple way of using register globals to make your gallery. I like the tutorial :)

Response to PHP : Easy gallery 2006-11-28 09:21:13


At 8/1/06 01:40 PM, Whabs wrote: 4. Now I will explain you the codeyou have to put!

First, the code:

<img src= "
<?
$src = $_GET [“image”]
echo $src
? >
“/>

Wouldn't that return an error?

Should use instead:

<img src="<?php $src = $_GET["image"]; echo $src; ?>" />

+ security concerns - the script doesn't check the directory of the path... you could easily send a string such as ../../images/private/img.jpg and the script would return it.


> twitter.

Response to PHP : Easy gallery 2006-11-28 10:24:26


It's extremly basic, and the user can view any image they want, and dig through your directorys.

Response to PHP : Easy gallery 2006-11-28 10:33:04


At 11/28/06 09:21 AM, different wrote:
At 8/1/06 01:40 PM, Whabs wrote: 4. Now I will explain you the codeyou have to put!

First, the code:

<img src= "
<?
$src = $_GET [“image”]
echo $src
? >
“/>
Wouldn't that return an error?

Should use instead:

<img src="<?php $src = $_GET["image"]; echo $src; ?>" />

+ security concerns - the script doesn't check the directory of the path... you could easily send a string such as ../../images/private/img.jpg and the script would return it.

Or you could make it simple by changing to this:

<img src="<?php echo $_GET['image'];?>" />

Response to PHP : Easy gallery 2006-11-28 14:02:16


hey, I just thought I would post my version of a gallery with no DB, it requires the pictures to be called pic-X.JPG but, it works well for me, and includes next and previous buttons to provide a more gallery feel.

function disp($pid) {
if (file_exists("pic-".$pid.".JPG")) {
echo "<img src=pic-".$pid.".JPG>";
echo "<br><br>";
if (file_exists("pic-".($pid-1).".JPG")) {
echo "Previous &nbsp; ";
}
if (file_exists("pic-".($pid+1).".JPG")) {
echo "Next";
}
} else {
echo "this file doesn't exist, try here";
}
}
if ($_GET['pid']) {
disp($_GET['pid']);
} else {
disp(1);
}

Response to PHP : Easy gallery 2006-11-28 14:07:21


hey, sorry I had no idea that the forum would butcher my code like that.

if you want a clean version there is one here:
code.is.here

Response to PHP : Easy gallery 2008-01-19 20:58:34


#
function disp($pid) {
#
      if (file_exists("pic-".$pid.".JPG")) {
#
            echo "<img src=pic-".$pid.".JPG>";
#
            echo "<br><br>";
#
            if (file_exists("pic-".($pid-1).".JPG")) {
#
                  echo "Previous &nbsp; ";
#
            }
#
            if (file_exists("pic-".($pid+1).".JPG")) {
#
                  echo "Next";
#
            }
#
      } else {
#
            echo "this file doesn't exist, try here";
#
      }
#
}
#
 
#
### code for displaying:
#
 
#
if ($_GET['pid']) {
#
      disp($_GET['pid']);
#
} else {
#
      disp(1);
#
}

Use code tags.

Response to PHP : Easy gallery 2008-01-19 21:28:37


Dude, it's from fuckin '06 - There weren't code tags back then


BBS Signature