PHP : Easy gallery
- eWhabs
-
eWhabs
- Member since: May. 4, 2006
- Offline.
-
- Forum Stats
- Member
- Level 13
- Blank Slate
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)
- WoogieNoogie
-
WoogieNoogie
- Member since: Jun. 26, 2005
- Offline.
-
- Forum Stats
- Member
- Level 15
- Programmer
This is a very simple way of using register globals to make your gallery. I like the tutorial :)
- different
-
different
- Member since: Jul. 8, 2004
- Offline.
-
- Forum Stats
- Member
- Level 35
- Blank Slate
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.
- Gutya
-
Gutya
- Member since: Nov. 27, 2006
- Offline.
-
- Forum Stats
- Member
- Level 07
- Blank Slate
It's extremly basic, and the user can view any image they want, and dig through your directorys.
- seel
-
seel
- Member since: Jun. 27, 2005
- Offline.
-
- Forum Stats
- Member
- Level 21
- Musician
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!Wouldn't that return an error?
First, the code:
<img src= "
<?
$src = $_GET [“image”]
echo $src
? >
“/>
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'];?>" />
- cvncpu
-
cvncpu
- Member since: Mar. 14, 2005
- Offline.
-
- Forum Stats
- Member
- Level 27
- Blank Slate
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 ";
}
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);
}
- cvncpu
-
cvncpu
- Member since: Mar. 14, 2005
- Offline.
-
- Forum Stats
- Member
- Level 27
- Blank Slate
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
- Shadow00881
-
Shadow00881
- Member since: Aug. 7, 2006
- Offline.
-
- Forum Stats
- Member
- Level 06
- Blank Slate
#
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 ";
#
}
#
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.
- Itsover9000
-
Itsover9000
- Member since: Aug. 7, 2007
- Offline.
-
- Forum Stats
- Member
- Level 10
- Blank Slate
Dude, it's from fuckin '06 - There weren't code tags back then


