Gallery [Add-on]
Resquested by -=insane=-
First off, run:
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
<? //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'>https:// <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
<? //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='https://$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
<? //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='https://$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
<? //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='https://$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
Is this possible?
Thanks
ratings... hard
xD
:
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