Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 373
0 Users 8 Guests Online

Gallery [Add-on]

Resquested by -=insane=-

First off, run:

Code

CREATE TABLE `image_requests` (
`id` int(10) NOT NULL auto_increment,
`username` varchar(225) NOT NULL default '',
`url` varchar(255) NOT NULL default '',
`image` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;

CREATE TABLE `gallery` (
`id` int(10) NOT NULL auto_increment,
`image` varchar(225) NOT NULL default '',
`username` varchar(225) NOT NULL default '',
`url` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;


in PHPmyADMIN

now, first page is submit image

so make a new file and call it submitimage.php

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<? //subitimage.php
session_start();
//starts session
include("config.php" );
// includes the config file
if ($logged["username"]) {
//checks user is logged in
switch ($_GET["page"]) {
// allow multiple pages
default:
if (
$_POST["submit"]) {
//check if forum was submitted
function findexts($filename)
{
$filename strtolower($filename) ;
$exts split("[/\\\\\\\\.]"$filename) ;
$n count($exts)-1;
$exts $exts[$n];
return 
$exts;
}
$ext findexts($_FILES['image']['name']);
$ran rand() ;
$ran2 $ran.".";
$target "images/";
//destination
$target $target $ran2.$ext;
if (
move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
$image $target;
$username strip_tags(htmlspecialchars($logged["username"]));
//username
$url htmlspecialchars($_POST["url"]);
// orignal url
$do mysql_query("INSERT INTO `image_requests` ( `username` , `url` , `image` ) VALUES ( '$username' , '$url' , '$image' ) ");
echo 
"Your image has been submitted, an admin now must accept it";
// echo this message
} else {
echo 
"There was a problem uploading your file";
//else error
}
} else {
echo 
"<form enctype='multipart/form-data' method='POST'>
<table cellspacing='0'>
<tr>
<td colspan='2'>Image</td>
<td colspan='2'><input type='file' size='30' name='image'></td>
</tr>
<tr>
<td colspan='2'>Original url</td>
<td colspan='2'>http:// <input type='text' size='30' name='url'></td>
<td colspan='4' align='center'><input type='submit' name='submit' value='Upload'> </td>
</tr>
</table>
</form>"
;
//echos form
}
break;
}
} else {
echo 
"you need to be logged in";
// not logged in
}
?>


ok, now we will make the gallery page where the images will display

so make a new page and call it gallery.php

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<? //gallery.php
session_start(); //starts session

include ( "config.php" ); // includes config

$display mysql_query"SELECT * FROM `gallery` ORDER BY `id` ASC " ); // get values
while ($imgs mysql_fetch_array($display))
{

echo 
"<table width='900'>
<tr>
<td width='300'><a href='http://
$imgs[url]' target='_BLANK'><img src='$imgs[image]' height='250' width='250'></a>
<a href='members.php?user=
$imgs['username']'>$imgs[username]</a></td>
</tr>
</table>"
//echos the image
}
?>


nice and easy so far :)

now the admin page to accept or delete the image

so make a new php page and call it gallery_admin.php

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<? //gallery_admin.php
session_start();
// starts session
include("config.php" );
$id = (int) $_GET['id']; //secure the id for SQL Injections
//includes config
if($logged['username'] && $logged['userlevel'] == 6){
//checks if logged in and admin
switch($_GET['page']){
// allows multiple pages
default: // main page
$display mysql_query("SELECT * FROM `image_requests` ORDER BY `id` ASC" );
//get requests
while ($imgs mysql_fetch_array($display)) {
echo 
"<table width='900'>
<tr>
<td width='300'><a href='http://
$imgs[url]' target='_blank'><img src='$imgs[image]' height='250' width='250'>
<i>Submitted by:</i><a href='members.php?user=
$imgs[username]'>$imgs[username]</a>
<a href='gallery_admin.php?page=accept&id=
$imgs[id]'> | <a href='gallery_admin.php?page=delete&id=$imgs[id]'></td>
</tr>
</table>"
;
//displays requests
}
break;
//end
case 'accept':
//accept page
if($_GET["id"]){
//get id from address bar
$get mysql_query("SELECT * FROM `image_requests` WHERE `id` = '$id' ");
// get requests
$imgs mysql_fetch_array($get);
$accepted mysql_query("INSERT INTO `gallery` ( `username` , `image` , `url` ) VALUES ( '$imgs[username]' , '$imgs[image]' , '$imgs[url]' ) ");
//accept images
$delete mysql_query("DELETE FROM `image_requests` WHERE `id` = '$id' ");
//delete when accepted
echo "Image accepted";
//accepted
}else{
//or
echo("Could not get id");
// could not find the request
}
break;
//end
case 'delete':
// delte page
if ($id) {
//gets is
$delete mysql_query("DELETE FROM `image_requests` WHERE `id` = '$id' ");
//deltes
echo("Image deleted and not accepted" );
// tells u image is deleted
}else{
//or
echo("Could not get id");
//could not find request
}
break;
//end
}
//end switch
}else{
//or
echo("You are not logged in or are not an admin" );
//not logged in or not admin
}
//end
?>


finally, gallery.php

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<? //gallery.php
session_start(); //starts session

include ( "config.php" ); // includes config

$display mysql_query"SELECT * FROM `gallery` ORDER BY `id` ASC " ); // get values
while ($imgs mysql_fetch_array($display))
{

echo 
"<table width='900'>
<tr>
<td width='300'><a href='http://
$imgs[url]' target='_BLANK'><img src='$imgs[image]' height='250' width='250'></a>
<a href='members.php?user=
$imgs[username]'>$imgs[username]</a></td>
</tr>
</table>"
//echos the image
}
?>


And that's it

any problems please leave a comment and ill help you out

Thanks
Chris
new2old
Author:
Views:
4291
Rating:
Posted on Sunday 5th October 2008 at 12:11 PM
darksway
darksway
is there a way to allow only friends to access the gallery? i have looked at coding this but i am find it very hard to follow. Your friends system has come in quite handy but id like to see the gallery add-on improved to allow only friends to access it.

Is this possible?

Thanks
Posted on Saturday 4th October 2008 at 05:27 AM
UrbanTwitch
UrbanTwitch
description... mega easy
ratings... hard
xD
Posted on Friday 3rd October 2008 at 01:10 PM
Nathan
Nathan
urban even add a description that would be cool and a rating system with it :)
Posted on Friday 3rd October 2008 at 05:45 AM
UrbanTwitch
UrbanTwitch
I am going to add more feature to this. :-) Such as pagination, bbcode, comments, and other things. if that is ok.
Posted on Thursday 2nd October 2008 at 05:54 AM
jambomb
jambomb
any help on mine lol.. just suddenly skipped passed it lol
Posted on Wednesday 1st October 2008 at 10:08 PM
UrbanTwitch
UrbanTwitch
Nvm, I fixed.
Posted on Wednesday 1st October 2008 at 09:57 PM
UrbanTwitch
UrbanTwitch
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/jsfdan/public_html/gallery.php on line 13

:
Posted on Tuesday 19th August 2008 at 08:28 PM
angieluckyd
angieluckyd
ohhh is that it?? lol thank you soo much ims till getting the hang of php :)
Posted on Tuesday 19th August 2008 at 08:16 PM
Dava
Dava
have you created the folder called images because that is what its saying
Posted on Tuesday 19th August 2008 at 07:42 PM
angieluckyd
angieluckyd
Hey I keep getting this error?? and itis when i try to upload i am really confused?? is there anyone who can help?

Warning: move_uploaded_file(images/988020794.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/chatuh/public_html/chat/pages/account/submitimage.php on line 28

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpDFLUyg' to 'images/988020794.jpg' in /home/chatuh/public_html/chat/pages/account/submitimage.php on line 28
There was a problem uploading your file