Php upload photos script

Reply

Join Date: Mar 2009
Posts: 8
Reputation: 1baxter1 is an unknown quantity at this point 
Solved Threads: 0
1baxter1 1baxter1 is offline Offline
Newbie Poster

Php upload photos script

 
0
  #1
Mar 21st, 2009
Hi im having abit of trouble adapting a tutorial i found on nettuts for creating a photography website heres the link if you wanna check it out:

http://net.tutsplus.com/videos/scree...-a-photo-site/

Anyways this code is fine, although because i have several categories of photos i need to store them in seperate tables, was wondering if i could use a drop down box to let the user choose the table where they want the photos to go. Any help is greatly appreciated.

ive posted the code below for the admin page. i included the select box i just dont have a clue on the php side of things thanks again.

  1.  
  2. <?php
  3.  
  4. require 'config.php';
  5. require 'functions.php';
  6. require 'common.php';
  7.  
  8. if(isset($_FILES['fupload'])) {
  9.  
  10. $filename = addslashes($_FILES['fupload']['name']); //get image user inputs
  11. $source = $_FILES['fupload']['tmp_name']; // temp directory where image is stored
  12. $target = $path_to_image_directory . $filename;
  13. $description = addslashes($_POST['description']);
  14. $src = $path_to_image_directory . $filename;
  15. $tn_src = $path_to_thumbs_directory . $filename;
  16.  
  17.  
  18. // Validates the form input
  19.  
  20. if(strlen($_POST['description']) < 5) // validates user inputted something larger than 5 characters long
  21. $error['description'] = '<p class="alert">Please enter a description for the photo. </p>';
  22.  
  23. if($filename == '' || !preg_match('/[.](jpg)|(gif)|(png)|(jpeg)$/', $filename)) // check user chose a picture to upload
  24. $error['no_file'] = '<p class="alert">Please select an image to upload </p>';
  25.  
  26. if(!$error) {
  27. move_uploaded_file($source, $target); // move image from temporary directory
  28.  
  29. $q = "INSERT into photo(description, src, tn_src) VALUES('$description', '$src', '$tn_src')"; //update database
  30. $result = $mysqli->query($q) or die(mysqli_error($mysqli));
  31.  
  32. if($result) {
  33. echo "Your Photograph has been uploaded";
  34. }
  35.  
  36. createThumbnail($filename);
  37.  
  38. } // end preg_match
  39. }
  40.  
  41. ?>
  42. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  43. <html>
  44.  
  45. <head>
  46. <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  47. <link rel="stylesheet" href="css/default.css" />
  48. <title>My Photos</title>
  49. </head>
  50.  
  51. <body>
  52. <h1>My Photos</h1>
  53. <ul><?php getPhotos(); ?></ul>
  54.  
  55. <h1>Upload a Photo</h1>
  56.  
  57. <form enctype="multipart/form-data" method="post" action="admin.php">
  58. <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
  59. <p><input type="file" name="fupload" /></p>
  60.  
  61. <p><label for="description">Enter a Description: </label>
  62. <textarea rows="6" cols="50" id="description" name="description"></textarea></p>
  63.  
  64. <p> <select name="catagory">
  65. <option value="sports">Sports</option>
  66. <option value="london">London</option>
  67. <option value="macro">Macro</option>
  68. <option value="landscapes">Landscapes</option>
  69. <option value="local">Local</option>
  70. </select>
  71.  
  72. <p><input type="submit" value="Upload Photo" name="submit" /></p>
  73. </form>
  74.  
  75. <?php
  76. if ($error['no_file']) echo $error['no_file'];
  77. if ($error['no_catagory']) echo $error['no_catagory'];
  78. if ($error['description']) echo $error['description'];
  79. ?>
  80.  
  81. <br />
  82. <a href="deletephoto.php">Delete A Photo</a>
  83.  
  84. </body>
  85. </html>
Last edited by peter_budo; Mar 21st, 2009 at 3:40 pm. Reason: Please use [code][/code] instead of <code></code>
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 28
Reputation: nathenastle is an unknown quantity at this point 
Solved Threads: 2
nathenastle's Avatar
nathenastle nathenastle is offline Offline
Light Poster

Re: Php upload photos script

 
0
  #2
Mar 25th, 2009
hi this is nathen i think this is usefull some what for you,
  1. $uploaddir="uploads/deals/";
  2. $filetype1=$_FILES[userfile][type];
  3. $filename=$_FILES[userfile][name];
  4. $realpath=$uploaddir.$filename;
  5. if(!empty($filetype1))
  6. {
  7.  
  8. if(move_uploaded_file($_FILES['userfile']['tmp_name'],$realpath ))
  9. {
  10.  
  11. }
  12.  
  13. /************************************Resizing the image 75x75****************/
  14. $path="uploads/deals";
  15. $bgim_file_name = $path."/".$filename;
  16. $bgimage_attribs = getimagesize($bgim_file_name);
  17.  
  18. if($filetype1=='image/gif')
  19. {
  20. $bgim_old = imagecreatefromgif($bgim_file_name);
  21. }
  22. else
  23. {
  24. $bgim_old = imagecreatefromjpeg($bgim_file_name);
  25. }
  26.  
  27. $bgth_max_width = 75; //for Album image
  28. $bgth_max_height = 75;
  29. $bgratio = ($bgwidth > $bgheight) ? $bgth_max_width/$bgimage_attribs[0] : $bgth_max_height/$bgimage_attribs[1];
  30.  
  31. $bgth_width = 75;//$image_attribs[0] * $ratio;
  32. $bgth_height = 75;//$image_attribs[1] * $ratio;
  33.  
  34. $bgim_new = imagecreatetruecolor($bgth_width,$bgth_height);
  35. imageantialias($bgim_new,true);
  36. $bgth_file_name = "uploads/deals/thumbnails/$filename";
  37.  
  38. imagecopyresampled($bgim_new,$bgim_old,0,0,0,0,$bgth_width,$bgth_height, $bgimage_attribs[0], $bgimage_attribs[1]);
  39.  
  40. if($filetype1=='image/gif')
  41. {
  42. imagegif($bgim_new,$bgth_file_name,100);
  43. }
  44. else
  45. {
  46. imagejpeg($bgim_new,$bgth_file_name,100);
  47. }
  48.  
  49. }
Last edited by peter_budo; Mar 26th, 2009 at 11:15 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC