Photo Gallery

Thread Solved

Join Date: Mar 2008
Posts: 12
Reputation: camdes is an unknown quantity at this point 
Solved Threads: 0
camdes camdes is offline Offline
Newbie Poster

Photo Gallery

 
0
  #1
Apr 21st, 2008
I am trying to create a photo gallery and there are various reasons why I need to create it from scratch. Below is the code for my upload file and I have been building it gradually. I have now added the resize function. I had placed this function in a separate PHP file which I called with e require. The function was not found so I embedded it in the file but I get the following error:
Parse error: syntax error, unexpected $end in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 114 (this is the last line of my file) Can someone help with my code.

  1. <?php
  2. $uploadid = $_SESSION['loginID'];
  3. $uploaddate = date("j-n-y, G:i:s");
  4.  
  5. $userfile_name=$HTTP_POST_FILES['userfile']['name'];
  6. $userfile_size=$HTTP_POST_FILES['userfile']['size'];
  7. $userfile_type=$HTTP_POST_FILES['userfile']['type'];
  8.  
  9. $ph_category=$HTTP_POST_VARS['category'];
  10. $ph_caption=$HTTP_POST_VARS['caption'];
  11.  
  12. if ($ph_category == "Select Category") {
  13. echo ("You have not selected a category for this photograph<BR>\n");
  14. exit;
  15. }
  16.  
  17.  
  18. //check to see if a file is uploaded at all
  19.  
  20. if ($userfile_size >= 2000000) {
  21. echo ("This file is too large<BR>\n");
  22. echo ("Please reduce the resolution or size of photograph<BR>\n");
  23. echo ("The file size must be below 2 megabytes and try again<BR>\n");
  24. exit;
  25. }
  26.  
  27. //echo ("upload id: $uploadid<BR>\n");
  28. echo ("upload date: $uploaddate<BR>\n");
  29. echo ("category: $ph_category<BR>\n");
  30. echo ("new file name: $userfile_name<BR>\n");
  31. echo ("caption: $ph_caption<BR>\n");
  32.  
  33.  
  34. $photoname="../gallery/$userfile_name";
  35.  
  36. //check for empty file
  37. echo ("filesize: $userfile_size<BR>\n");
  38.  
  39. if ($userfile_size==0)
  40. {
  41. echo "Error: File uploaded has no image";
  42. exit;
  43. }
  44.  
  45. //set upload directory (below) to whatever you need on the server
  46.  
  47. $photoupfile = "../gallery/$userfile_name";
  48.  
  49. if ( !copy($userfile, $photoupfile))
  50. {
  51. echo "Error: Could not save file. <br>.mysql_error())";
  52. exit;
  53. }
  54. //report file upload successful!
  55.  
  56. echo "$photoname uploaded successfully!<br>";
  57.  
  58. // Resize photographs
  59.  
  60. function createsmall($name, $filename, $new_w, $new_h){
  61. $system=explode('.',$name);
  62. if (preg_match('/jpg|jpeg/',$system[1])){
  63. $src_img=imagecreatefromjpeg($name);
  64. }
  65. if (preg_match('/png/',$system[1])){
  66. $src_img=imagecreatefrompng($name);
  67. }
  68. $old_x=imageSX(src_img);
  69. $old_y=imageSY($src_img);
  70. if ($old_x > $old_y) {
  71. $small_w=$new_w;
  72. $small_h=$old_y*($new_w/$old_x);
  73. }
  74. if ($old_x < $old_y) {
  75. $small_w=$old_x*($new_w/$old_y);
  76. $small_h=$new_h;
  77. }
  78. if ($old_x == $old_y) {
  79. $small_w=$new_w;
  80. $small_h=$new_h;
  81. }
  82. $dst_img=ImageCreateTrueColor($small_w,$small_h);
  83. imagecopyresampled($dst_img,$src_img,0,0,0,0,$small_w,$small_h,$old_x,$old_y);
  84. if (preg_match('/png/',$system[1])) {
  85. imagepng($dst_img,$filename);
  86. } else {
  87. imagejpeg($dst_img,$filename);
  88. }
  89. imagedestroy($dst_img);
  90. imagedestroy($src_img);
  91.  
  92.  
  93.  
  94. createsmall('$photoname','../gallery/images/i_$userfile_name',640,640);
  95. createsmall('$photoname','../gallery/thumbs/t_$userfile_name',70,70);
  96.  
  97. $new_image=('../gallery/images/i_$userfile_name');
  98. $new_thumb=('../gallery/thumbs/t_$userfile_name');
  99.  
  100. $query = "INSERT INTO gallery_photos (photo_filename, photo_thumbnail, photo_caption, photo_category, upload_id, upload_date )". "VALUES ('$new_image','$new_thumb','$ph_caption', '$ph_category','$uploadid','$uploaddate')";
  101.  
  102. //echo ("The query is: <BR>$query<P>\n");
  103.  
  104. if (mysql_db_query ($dbname, $query, $link)){
  105. echo ("Your Photograph was successfully uploaded!<BR>\n");
  106. } else {
  107. echo(mysql_error());
  108. echo ("Your photograph could not be uploaded.<BR>\n");
  109. }
  110. mysql_close ($link);
  111. ?>
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 6
Reputation: bad_dreams99 is an unknown quantity at this point 
Solved Threads: 2
bad_dreams99 bad_dreams99 is offline Offline
Newbie Poster

Re: Photo Gallery

 
0
  #2
Apr 21st, 2008
You don't seem to close off your function at the end. This is why you're getting an $end parse error.
Last edited by bad_dreams99; Apr 21st, 2008 at 6:59 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 12
Reputation: camdes is an unknown quantity at this point 
Solved Threads: 0
camdes camdes is offline Offline
Newbie Poster

Re: Photo Gallery

 
0
  #3
Apr 22nd, 2008
Thank you for that, I have now closed the function and get:
Warning: imagesx(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 68

Warning: imagesy(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 69

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 83

Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 90

Warning: imagesx(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 68

Warning: imagesy(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 69

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 83

Warning: imagedestroy(): supplied argument is not a valid Image resource in C:\wamp\www\phototest\reqfiles\submit_photos_resize.req.php on line 90
Your Photograph was successfully uploaded!

Warning: Unexpected character in input: ''' (ASCII=39) state=1 in C:\wamp\www\phototest\reqfiles\image_functions.req.php on line 26

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\phototest\reqfiles\image_functions.req.php on line 26
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 6
Reputation: bad_dreams99 is an unknown quantity at this point 
Solved Threads: 2
bad_dreams99 bad_dreams99 is offline Offline
Newbie Poster

Re: Photo Gallery

 
0
  #4
Apr 22nd, 2008
You need to open your image using something like this:
  1. $tmpName = $HTTP_POST_FILES['userfile']['tmp_name'];
  2.  
  3. $fp= fopen($tmpName, 'r');
  4. $content = fread($fp, filesize($tmpName));
  5. $content = addslashes($content);
  6. fclose($fp);

then use the $content variable to store/modify, as it is your actual image. Also, i'm using tmp_name because it allows us to use a temporary clone of the original image for safetys sake.

There were a lot of errors there, so hopefully that gets rid of the invalid image ones.
Last edited by bad_dreams99; Apr 22nd, 2008 at 2:13 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC