Gallery [Add-on]


Resquested by -=insane=-

First off, run:

PHP Code
  1. CREATE TABLE `image_requests` (
  2. `id` int(10) NOT NULL auto_increment,
  3. `username` varchar(225) NOT NULL default '',
  4. `url` varchar(255) NOT NULL default '',
  5. `image` varchar(255) NOT NULL,
  6. PRIMARY KEY (`id`)
  7. ) ENGINE=MyISAM;
  8.  
  9. CREATE TABLE `gallery` (
  10. `id` int(10) NOT NULL auto_increment,
  11. `image` varchar(225) NOT NULL default '',
  12. `username` varchar(225) NOT NULL default '',
  13. `url` varchar(255) NOT NULL default '',
  14. PRIMARY KEY (`id`)
  15. ) ENGINE=MyISAM;


in PHPmyADMIN

now, first page is submit image

so make a new file and call it submitimage.php

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


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. <? //gallery.php
  2. session_start(); //starts session
  3.  
  4. include ( "config.php" ); // includes config
  5.  
  6. $display = mysql_query( "SELECT * FROM `gallery` ORDER BY `id` ASC " ); // get values
  7. while ($imgs = mysql_fetch_array($display))
  8. {
  9.  
  10. echo "<table width='900'>
  11. <tr>
  12. <td width='300'><a href='https://$imgs[url]' target='_BLANK'><img src='$imgs[image]' height='250' width='250'></a>
  13. <a href='members.php?user=$imgs['username']'>$imgs[username]</a></td>
  14. </tr>
  15. </table>"; //echos the image
  16. }
  17. ?>


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


finally, gallery.php

PHP Code
  1. <? //gallery.php
  2. session_start(); //starts session
  3.  
  4. include ( "config.php" ); // includes config
  5.  
  6. $display = mysql_query( "SELECT * FROM `gallery` ORDER BY `id` ASC " ); // get values
  7. while ($imgs = mysql_fetch_array($display))
  8. {
  9.  
  10. echo "<table width='900'>
  11. <tr>
  12. <td width='300'><a href='https://$imgs[url]' target='_BLANK'><img src='$imgs[image]' height='250' width='250'></a>
  13. <a href='members.php?user=$imgs[username]'>$imgs[username]</a></td>
  14. </tr>
  15. </table>"; //echos the image
  16. }
  17. ?>


And that's it

any problems please leave a comment and ill help you out

Thanks
Chris
new2old's Avatar
Author:
Views:
5,765
Rating:
Posted on Sunday 5th October 2008 at 12:11 PM
darksway
darksway's Avatar
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's Avatar
description... mega easy
ratings... hard
xD
Posted on Friday 3rd October 2008 at 01:10 PM
Nathan
Nathan's Avatar
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's Avatar
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's Avatar
any help on mine lol.. just suddenly skipped passed it lol
Posted on Wednesday 1st October 2008 at 10:08 PM
UrbanTwitch
UrbanTwitch's Avatar
Nvm, I fixed.
Posted on Wednesday 1st October 2008 at 09:57 PM
UrbanTwitch
UrbanTwitch's Avatar
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's Avatar
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's Avatar
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's Avatar
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