Building the back-end of a photo site

Building the Back-End of a Photo Site

Nov 27th, 2008 in Screencasts by Jeffrey Way

For those of you who have been following the last few screencasts, you must have noticed that each tutorial has been centered around a "photo site" theme. (See Scanning Folders With PHP, How to Dynamically Create Thumbnails, and Create a Photo-Admin Site Using PHP and jQuery. Today, we'll build the backend for a photo site. This tutorial will teach you how to add, delete, and update photos.

PG

Author: Jeffrey Way

Hi, I'm Jeff. I'm the editor of Nettuts+, and the Site Manager of both ThemeForest, and CodeCanyon. I spend too much time in front of the computer and find myself telling my fiance', "We'll go in 5 minutes!" far too often. I just can't go out to dinner while I'm still producing FireBug errors...drives me crazy. During my free time, I sporadically write articles for my own personal blog. If it will keep you in the good graces of the church, follow us on Twitter.

Our Mission

  • Create a database that will store our images.
  • Create a home page that retrieves all of the photos that are stored in our database.
  • Allow the user to upload photos.
  • Write some validation to ensure that the user enters a proper description and chooses an image
  • Use jQuery to allow the user to asynchronously update and delete specific photos.

There is simply too much to cover as a written tutorial. I've included a few key points. Refer to the screencast for the complete tutorial.

The Database Structure

The database structure

Get the Photos From the Database

Get Photos Function
function getPhotos() {
	require 'database.php';
	$q = "SELECT id, tn_src FROM photo ORDER BY id desc";
	
	$result = $mysqli->query($q) or die($mysqli_error($mysqli));
	
	if($result) {
		while($row = $result->fetch_object()) {
			$tn_src = $row->tn_src;
			$src = $row->src;
			$id = $row->id;
		
			print '
  • <a href="review_image.php?id=' . $id . '"> <img src="' . $tn_src . '" alt="images" id="' . $id . '" /> </a> </li>'; print "\n"; } } }
  • Upload Photos

    Get Photos Function

    Form Validation

        if(strlen($_POST['description']) < 4) 
        $error['description'] = '

    Please enter a description for your photo.

    '; if($filename == '' || !preg_match('/[.](jpg)|(gif)|(png)|(jpeg)$/', $filename)) $error['no_file'] = '

    Please select an image, dummy!

    ';

    Update the Photo's Description Asynchronously

    Get Photos Function
    $('#description').click(function() {
                var originalelement = this;
                var currentText = $(this).text();
    
    			$(this).fadeOut(100).before('');
    		
    		    $('#input').livequery('change', function() {
    	            var id = <?php echo $_GET['id'] ?>;
    			    var thisparam = this;
                    var newText = $(this).val();
                    
                    if (newText == '') {
                       newText = 'Please enter a description'; 
                    }
                              
    	            $.ajax({
    	                type: 'post',
    	                url: 'updatePhoto.php',
    	                data: 'id=' + id + '&description=' + newText,
    	    
    	                success: function() {
                            $(thisparam).remove();
    	                    $(originalelement).text(newText).fadeIn(1000);
    	                }
    	           });
                    
    		    });
    		});
    	});
    

    UpdatePhoto.PHP

    require 'database.php';
    
    $id = $_POST['id'];
    $d = addslashes($_POST['description']);
    
    if ($d == '') $d = 'Click here to enter a description.';
    
    $q = "UPDATE photo SET description='$d' WHERE id = $id"; 
    $result = $mysqli->query($q) or die('There was a problem updating this information.');
    
    if($result) echo "Your photo has been successfully updated.";
    

    Delete a Photo

    Get Photos Function
    	$(function() {
    		$('img').click(function() {
    		   	var id = $(this).attr('id');
    		   	var thisparam = $(this);
    			   	
    			$.ajax({
    				type: 'post',
    				url: 'delete.php',
    				data: 'id=' + id,
    				
    				success: function() {
    		
    					$(thisparam).parent('li').fadeOut('slow');
                        $('#result').remove();
    					var response = '

    Success. The image has now been removed!

    '; response += 'Return to Home Page
    '; $('body').append(response); } }); }); })

    Delete.PHP

    require 'database.php';
    
    $id = $_POST['id'];
    
    $q = "DELETE from photo WHERE id = $id";
    $result = $mysqli->query($q) or die("There was a problem!");
    
    if($result) header("location: index.php");
    

    Completion

    So that does it. You could implement a bit more security into this application. But the idea is that these pages would already be secured by using something similar to an ht-access file. From here on, the sky is the limit. You should consider adding tags to your images, creating albums, etc. This should get you started.


    Related Posts

    Check out some more great tutorials and articles that you might like

    Enjoy this Post?

    Your vote will help us grow this site and provide even more awesomeness

    Plus Members

    Source Files, Bonus Tutorials and
    More for $9 a month for all TUTS+
    sites in one subscription.

    Join Now

    User Comments

    ( ADD YOURS )
    1. PG

      Manji November 27th

      Thank you!

      ( Reply )
    2. PG

      insic November 27th

      this tutorial is sweet! its very helpful, perfect for my next project.

      ( Reply )
    3. PG

      yusuf1 November 27th

      thats really nice, was looking for something along this lines.cheers!

      ( Reply )
    4. PG

      T Pham November 27th

      great, thanks for tut.

      ( Reply )
    5. PG

      Amr November 27th

      3 in 1 tut … ;)
      thanks for this tut!

      ( Reply )
    6. PG

      Janko November 27th

      Nice one. Would be interesting to do one in ASP.NET

      ( Reply )
    7. PG

      pixelsoul November 27th

      Very nice. I know that this would come in handy when the turn key solutions just won’t work for the project.

      ( Reply )
    8. PG

      Kailash Gyawali November 27th

      wow, this is what i have been looking for to learn and this is just perfect, thanks a lotttttt, nettuts RULESSS!!!!, keep up the work guys

      ( Reply )
    9. PG

      Kim Dolleris November 27th

      Yay!!! Thanks!

      ( Reply )
    10. PG

      Shane November 27th

      Thanks Jeff – nice post.

      I see you’ve updated the getPhotos function so that it writes out lower case tags now :)

      ( Reply )
    11. PG

      ashvin November 27th

      Jeff u r the man and nettuts u r the blog!!

      Thanx!

      ( Reply )
    12. PG

      Dan Harper November 27th

      Nice video, Jeffrey!

      Although I find the American way of pronouncing “database” annoying for some reason haha. It’s day-ta-base.

      ( Reply )
    13. PG

      Melvin Walls November 27th

      Thanks Jeff you rule! I followed it from start to finish great work

      ( Reply )
    14. PG

      Brenley Dueck November 27th

      Outstanding tutorial. It is amazing what you can all accomplish with JQuery. AJAX is pretty simple when using it.

      ( Reply )
    15. PG

      Jonathan Solichin November 27th

      Awesome tut! Thanks, I was looking for something like this.

      ( Reply )
    16. PG

      Miles Johnson November 27th

      The PHP in this tutorial is a bit weak but the jQuery is good. You should NEVER print/echo information within a function, only do returns. You should also never put the php and html in the same files, it should be separated using a template system.

      ( Reply )
    17. PG

      Jonas November 27th

      Delete.php allows for SQL injections by malicious users. It would be so easy to delete tables or alter data using that file alone.

      Try mysqli_real_escape_string().

      ( Reply )
    18. PG

      Moksha November 27th

      great video thanks,

      ( Reply )
    19. PG

      Chris November 27th

      The argument from Miles Johnson about the print/echo within a function and from Jonas about the SQL injections are good ones, but its not the topic here.
      Very clear and helpful cast, thanks for sharing.

      ( Reply )
    20. PG

      Ryan November 28th

      Very helpful, will be great to use for clients who want to be able to maintain the website themselves!

      ( Reply )
    21. PG

      Jonas November 28th

      @Chris: Sure security/SQL injections isn’t the topic here, but since making the script secure would only take one more line of code *and* this site is read by a lot of newbie developers who might not know about security, it’s important that the scripts shown here are secure.

      Given that the security problem of SQL injections has been talked about since … forever, I’m frankly a little shocked that there are experienced or semi-experienced developers out there who write code that allows for SQL injections.

      ( Reply )
    22. PG

      Danc November 28th

      Excellent tutorial, many thanks, but I was wondering if it was possible to edit multiple entries on one page with this code?

      I have tried and failed but any tips would be welcome!

      Cheers,

      ( Reply )
    23. PG

      Joao Clerigo November 28th

      Excelent TUT. Maybe this is a stupid question, but why not use imagecopyresampled instead of imagecopyresized in the function createThumbnail? I’ve picked up your tut to test and noticed that the thumbs have jagged edges. I’ve already had built an auto thumb creator for some websites I’ve made and have been using the function imagecopyresampled instead of imagecopyresized that makes the resized thumbs resampled smoothly by interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity.

      ( Reply )
    24. PG

      Dan November 28th

      Cool indeed

      ( Reply )
    25. PG

      Dan November 28th

      At 29:51 in the screencast, you mention that getting the it is “probably not best practice to embed this PHP” when setting the id variable in javascript to .

      I’m curious, if that isn’t best practice, what would be a preferred alternative? Is there one?

      All in all Jeff, this was an awesome screencast. It was relaxing to watch as with most screencasts I’m trying to write code as fast as you type it…and not succeeding (but that’s just me :-P ).

      Thanks again!

      ( Reply )
    26. PG

      Ben Blogged November 29th

      Jeffrey you are the man!

      ( Reply )
    27. PG

      mindkkane November 29th

      THanks!!!
      For the guys who see not so best practice in the php code please give us novice some pointers so we can change it on our own. I would be thankful for any coding corrections,alternatives,or best practice pointers. Thanks again!!!!!

      ( Reply )
    28. PG

      Jonas November 29th

      @ mindkkane:

      Here’s a description of SQL injections and how to avoid them: http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php.

      As for other problems with the code: The getPhotos() function mixes XHTML with PHP. Ideally, the function should just return an object to a template. The template would then iterate over the object and print out the contents. This sort of functionality is included in MVC frameworks such as CakePHP (http://cakephp.org/) and Django (http://djangoproject.com/), so if you learn how to use them, you get that separation of code and XHTML automatically (because the systems enforce the separation).

      ( Reply )
    29. PG

      Jauhari November 30th

      Just Perfect Tutorials..

      ( Reply )
    30. PG

      grrrrrr8 November 30th

      awsome

      ( Reply )
    31. PG

      arma9 November 30th

      Keep it up with Jquery and Ajax !!!Thanx again

      ( Reply )
    32. PG

      Daniel November 30th

      Very nice tutorial. I really appreciate the hands on “real application” style tutorials here. You’re doing a great job Jeff. (and the others of course). This site is my no.1 bookmark if refreshing my memory on everyday tasks.

      I do agree with Jonas on the sql injection parts though. It takes very little extra code and time to add protection against this and it should be done at a site like this.

      Keep up the fantastic work, looking forward to the “plus” programme.

      ( Reply )
    33. PG

      Jamie Taniguchi November 30th

      Like Jonas mention with the vulnerability in Delete.php the same vulnerability exists in UpdatePhoto.php I believe it’s just the lax assumption on the authors part that $id will always be clean and will be what is expected (a number). I would hope that the tutorial is updated to at least put in the suggestion Jonas gave because a lot of users don’t read the comments section.

      While I agree with Chris that the comment made by Miles Johnson isn’t necessarily on topic to the tutorial the comment made by Jonas and security is a very important topic and what Jonas has pointing out is very much related to the tut. Aside from that great topic for a tut!

      ( Reply )
    34. PG

      silent November 30th

      I’ve been creating many photo site for my customer and I naver imagine that back-end could be this user friendly!

      Thank you for sharing it!

      ( Reply )
    35. PG

      kareem December 1st

      this is wonderful topic …. i will put acopy of this topic on
      my site here
      http://www.as7ap4you.com

      ( Reply )
    36. PG

      AKARATALARAB December 2nd

      GOOD, this is wonderful tutorial
      fantastic results AND IT will help me im my site
      http://www.akaratalarab.com

      ( Reply )
    37. PG

      Rodge December 2nd

      Very nice tut!!

      However, when I click the delete photo button (on the index page) I get this error:

      No input file specified.

      On the review page clicking on the delete button wont redirect me to index…

      ( Reply )
    38. PG

      Takumi86 December 2nd

      Cool tips dude, keep them coming

      ( Reply )
    39. PG

      Uncle December 2nd

      Hi Guys I’m a serious PHP Newbie so please be kind.

      I’ve created the database with the “photo” table and the fields above.

      When i run index.php all that gets outputted is this “”

      Can anyone offer some advice as to what i’ve done wrong?

      ( Reply )
    40. PG

      Torben Rasmussen December 5th

      Ok so i’ve tested it on xp, vista, running wamp with php 2,26 and on one.com’s servers, and its not working, not as intended anyway. theres something wrong with the upload / or move_uploaded_photo part, it write to the database with the image andress and you can delete it again, but theres no image in /images (or anywhere else) and i’m getting no errors on localhost (and yeah i got E_ALL on)

      Also on a sidenote, a sqldump would be appreciated for the lazy types like me :D but i like the whole idea around this tut, just gotta make it work..

      ( Reply )
    41. PG

      coven December 6th

      this is wonderful tutorial .. i read it 3 times and get a fantastic results and sure i put a
      copy of this lesson on my site here

      http://www.ac-coven.net

      ( Reply )
    42. PG

      Hahn December 9th

      i enjoy learning this good tutorial. can you please teach how to tag and search for photos too?

      ( Reply )
    43. PG

      Jeroen December 12th

      Awesome tutorial! Thanks a lot Jeff, you’re doing a great job on Nettuts.

      I also noticed the problem Torben Rasmussen was talking about.

      But i already found the cause,…. FILESIZE.
      If the image filesize is too big, the picture won’t be uploaded, but the database will add a record for it. Ack!
      Perhaps the filesize should also get a validation. Any suggestions on how to do this?

      ( Reply )
    44. PG

      Benn Garnish December 14th

      Im really struggling with this one, I’ve watched all the screencasts that are related to this one and im still in no-mans land about it all.

      It starts right at the begining really, the database is kicking out a mysqli error

      I have the correct information in my db_name and db_user and db_pass
      but this is as far as the script will go.

      Can anyone help me with this please and thank you :)

      ( Reply )
    45. PG

      Mike Schneider December 21st

      Benn I’m in the same boat as you. I’ll look over the code to see if there is an error or something. If I find anything I’ll post it here

      ( Reply )
    46. PG

      Aaron December 22nd

      @Benn and Mike

      I think you are referring to this error:

      Fatal error: Function name must be a string

      I got it too. Did some research and found out that there was a ‘$’ in front of mysqli_error on line 9 in functions.php where there shouldn’t be. That fixed it for me. Hope this helps

      ( Reply )
    47. PG

      Benn Garnish December 23rd

      Hey guys

      I worked out that for this to work you need php5 switched on your hosting server. How embarrassing.

      I was also struggling with images being added to the site but not displaying a thumbnail. But this was sorted as there wasn’t a final ‘else’ statement in the function for making the thumbnail image. Also the preg_match statements are case sensitive, so files with .JPG were not being added.
      So for this to be fixed i added this to the preg_match statements:

      if(preg_match(‘/[.]jpg$/’, strtolower($filename))) {
      $im = imagecreatefromjpeg($path_to_image_directory . $filename);
      } else if (preg_match(‘/[.]gif$/’, strtolower($filename))) {
      $im = imagecreatefromgif($path_to_image_directory . $filename);
      } else if (preg_match(‘/[.]png$/’, strtolower($filename))) {
      $im = imagecreatefrompng($path_to_image_directory . $filename);
      } else {
      print(“Error: The file ‘$filename’ is not a supported file type”);
      }
      }

      Hope this helps some of you.

      ( Reply )
      1. PG

        idrish February 7th

        Thanks a lot…This saved my day…a very handy tip worth noting…

        ( Reply )
    48. PG

      Greg December 27th

      What if the users need to email their photos as attachments instead of uploading via a form?

      ( Reply )
    49. PG

      whiskeyfrances December 27th

      This is great… With some extra coding and an ffmpeg-enabled hosting one could also take this to create a video site…

      ( Reply )
    50. PG

      pauli December 29th

      hi, im looking for some kind of plugin that let users upload their images on my website(wordpress) and as the admin it lets me choose which one to display
      also when uploading the images the users can put some text.

      ( Reply )
    51. PG

      Max January 7th

      I have been working with this tutorial a lot, and I have learned a lot form it!

      For the people with the MySQLi problem, replace each string that uses it with:
      $result = mysql_query($q) or die(mysql_error());
      Make sure you select your database in database.php.

      The only problem I am still having is how to prevent SQL injection on delete.php. Any help would be great.

      ( Reply )
    52. PG

      cdm January 8th

      hi
      First photo is uploaded but when try to upload second it displays error
      “Duplicate entry ‘0′ for key 1″
      where is problem? can anyone help?

      ( Reply )
    53. PG

      tn January 12th

      Love the tutorial – learnt heaps. Would love to know how to implement the album with the jQuery.
      “You should NEVER print/echo information within a function, only do returns. You should also never put the php and html in the same files, it should be separated using a template system”
      Could you please put me in the right direction for this – not knowing how to do this?
      Thanks.

      ( Reply )
    54. PG

      tn January 12th

      RE: Max
      I changed all to mysql but in database.php:
      $mysqli = new MySQLi($db_server, $db_user, $db_pass, $db_name) or die(mysqli_error());
      when I change it to MySQL it says there is no class for it and if I change anything else it won’t connect to the database at all and says on line 9 in functions is error.
      Fatal error: Function name must be a string

      I got it too. Did some research and found out that there was a ‘$’ in front of mysqli_error on line 9 in functions.php where there shouldn’t be. That fixed it for me. Hope this helps.
      I did this but it still didn’t work. Any other suggestions?
      Thanks.

      ( Reply )
    55. PG

      webdesign groningen January 20th

      Hi,

      Great tutorial. I was struggling with uploading images with php for a while. I’m a designer not a hardcore programmer, So this tutorial helped me out a lot.

      Greetings from groningen

      ( Reply )
    56. PG

      Willabee Wombat January 22nd

      When uploading, no error is displayed, an image link is displayed but no image. Looking in the image folder, no images have been created. I assume this is a permissions problem on an Windows NTFS partition. If I am in .NET I have to give the ASPNET account modify permission for this type of process.
      What account do I need to give permission in a PHP/Apache environment to make this application work?

      ( Reply )
    57. PG

      Willabee Wombat January 23rd

      OK tried again, brand Windows XP virtual machine in VMWare

      Installed latest WAMP

      Created myphotos DB and executed:

      CREATE TABLE IF NOT EXISTS `photo` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `description` text NOT NULL,
      `src` varchar(150) NOT NULL,
      `tn_src` varchar(150) NOT NULL,
      `album_id` tinyint(3) NOT NULL,
      PRIMARY KEY (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

      Copied your solution and browsed index.php

      Only modifications made was to remove the $ throughout all code as recommended by commenter’s to give:

      $result = $mysqli->query($q) or die(mysqli_error($mysqli));

      Uploaded image (jpg) and had the following errors:

      Notice: Undefined property: stdClass::$src in C:\wamp\www\newPhotoSite\functions.php on line 15

      Notice: Undefined variable: error in C:\wamp\www\newPhotoSite\index.php on line 67

      Notice: Undefined variable: error in C:\wamp\www\newPhotoSite\index.php on line 68

      Entries are being submitted to database ok.

      Nothing gets written to images or images/tn folders

      functions.php Line 15 is:
      $src = $row->src;

      index.php Line 67 and 68 is:
      if ($error['no_file']) echo $error['no_file'];
      if ($error['description']) echo $error['description'];

      Any help appreciated.

      ( Reply )
    58. PG

      polymaze January 26th

      Hello, I love the tutorial, however, I keep receiving an error message after I upload or delete an image (if deleting from individual photos).

      //after uploading an image
      Warning: Cannot modify header information – headers already sent by (output started at C:\xampp\htdocs\TESTS\newPhotoSite_backend\database.php:1) in C:\xampp\htdocs\TESTS\newPhotoSite_backend\functions.php on line 99

      //after deleting an image
      Warning: Cannot modify header information – headers already sent by (output started at C:\xampp\htdocs\newPhotoSite_backend\database.php:1) in C:\xampp\htdocs\newPhotoSite_backend\delete.php on line 11

      The lines the error messages are listing target the ( header(“location: index.php”); ) line.

      I’m not sure why I’m getting the error messages instead of the page redirecting back to the index, or how to fix the problem.

      Thanks

      ( Reply )
    59. PG

      David February 1st

      Just another great tutorial. Thanks Jeff.

      Just one problem little problem. When you delete an image its references are wiped out from the database but the image and the thumbnail are still there. Is there a way to delete these files too? As I’m quite new to PHP it’ll probably take a while since I figure it out myself. So if someone could give me hint where to look for a solution I’d be very thankful.

      ( Reply )
      1. PG

        Arkad September 18th

        havnt tried this but maybe just use the same code for deleting the original by making a duplicate and change the locations … maybe

        ( Reply )
    60. PG

      owain Llewellyn February 4th

      Thanks for this great tutorial Jeff.. I know you hinted that you may add a album field to the database so that you can store the images in different albums at a later date…

      Do you have any idea when you might be looking at doing this? As I’d love to learn how to upload images into different categories and then select them via category in a dropdown or something similar.

      Im also getting the same errors as polymaze above… even though the functions seem to work correctly and the photos get added to the database.

      Any ideas?

      ( Reply )
    61. PG

      Peter February 6th

      Wow, don’t know how to thank you, been banging my head against the wall for a couple of days trying to call on images to be displayed.
      Thanks again.

      ( Reply )
    62. PG

      Raman February 6th

      I was looking for something related to images for my next project and came across this tutorial. I am learning PHP, MySQL . With NETTUTS I think i can learn very fast and gain a solid hand in programming.

      Thanks for all the TUTS.

      ( Reply )
    63. PG

      math1as February 11th

      First fo all great work, but I need some help please

      When uploading a Image I get:
      Warning: Cannot modify header information – headers already sent
      by (output started at C:\Program Files\xampp\htdocs\myphoto
      \database.php:1) in C:\Program Files\xampp\htdocs\myphoto
      \functions.php on line 99
      similar to polymaze owain Llewellyn

      Then there is a problem when uploading from other partitions of my HD

      Finally how can i adjust the maximum file size

      I hope someone can help me thanks

      ( Reply )
    64. PG

      Terry February 12th

      can anyone tell me why i get this error?

      Fatal error: Cannot instantiate non-existent class: mysqli in /home/sites/eireloom.com/public_html/test/database.php on line 8

      ( Reply )
    65. PG

      Terry February 13th

      Never mind Jeffrey was able to sort it out for me, thanks again Jeffrey!

      ( Reply )
    66. PG

      Stephen February 24th

      I have learned a lot from this tutorial but I am banging my head against a brick wall now!

      I have tried to incorporate the “create dynamic thumbnails” tut files too, but each time I try to add an image nothing happens. The page refreshes, but nothing is added to the site or the database. I do not get an error message either. I am using localhost on a Vista machine.

      Any advice or pointers would be greatly appreciated.

      I would also like to add my vote to the security issue. I think security is paramount for any PHP script and advice/lines of code should be included with every tutorial as standard. I am a newbie to writing my own code, but I know PHP is open to exploitation by people who know what they are doing.

      ( Reply )
    67. PG

      AdryDesign March 1st

      Awesome Thanks for share!! :D

      Great tutorial !!!

      ( Reply )
    68. Did anyone else get an problem with the functions file?

      ( Reply )
    69. PG

      Jake April 12th

      I am having a problem with the functions file to and really have no idea what is wrong it is saying: Fatal error: Function name must be a string in /…/…/…l/…/photo/functions.php on line 9

      This is a great tutorial I have learnt a lot too…Thanks!

      ( Reply )
    70. PG

      MattyC April 13th

      Hi! looks like a perfect solution for my site, but i’m getting this message after uploading an image

      Success! Your file has been uploaded
      Fatal error: Call to undefined function imagecreatefromjpeg() in /Users/mattchinnock/Sites/photo/functions.php on line 74

      Can anyone help?

      ( Reply )
    71. PG

      Ross May 6th

      I am having lots of issues with functions.php and thumbnails are not being created.
      “Success! Your file has been uploaded
      Warning: imagecreatefromjpeg(images/news.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in ”

      “Warning: imagesx(): supplied argument is not a valid Image resource”

      Any help would be greatly appreciated – getting different errors for gif uploads compared with jpeg files (getting maybe 8 errors for jpegs and only 2 for gif)

      ( Reply )
    72. PG

      Jim Gaudet May 12th

      Sorry so late, and I hope you don’t mind helping. (Also I hope I get an email response for replies, I see no option probably because I am already subscribed)

      I have everything working with 1 question. I want the user to be able to upload many files at once with multiple selects. I was hoping they could select their files like normal with a thumbnail preview (using windows explorer or whatever) and select multiple images to upload at once…

      Can you explain how I could adapt this project to allow uploading multiple images at once?

      Thanks,

      ( Reply )
    73. PG

      owca June 5th

      Write function adding multiple fields and as name use array fupload[]. Then just use their elements as single files.

      ie sth like this

      $photos_uploaded = $_FILES['fupload'];

      while( $counter <= count($photos_uploaded) )
      {
      and here the rest of the functions

      ( Reply )
    74. PG

      Tim June 16th

      Hello,
      I have the same problem as polymaze.
      Is there someone that knows how to fix this.

      ————————————————————-
      //after uploading an image
      Warning: Cannot modify header information – headers already sent by (output started at C:\xampp\htdocs\TESTS\newPhotoSite_backend\database.php:1) in C:\xampp\htdocs\TESTS\newPhotoSite_backend\functions.php on line 99

      //after deleting an image
      Warning: Cannot modify header information – headers already sent by (output started at C:\xampp\htdocs\newPhotoSite_backend\database.php:1) in C:\xampp\htdocs\newPhotoSite_backend\delete.php on line 11

      The lines the error messages are listing target the ( header(”location: index.php”); ) line.

      ( Reply )
    75. PG

      luke July 2nd

      Please Help !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      hi this script is working perfect for me, i just have 1 problem…..

      i have created a login page just for me and it sends me to the upload a photo page..
      my upload form on the upload photo page, uploads the picture and sends it to the selected page for example. cats.php. but when i upload to cats.php the picture also gets sent to dogs.php and every other page…
      the reason i think it does this is because all pages have the getPhotos() function. please could any1 help me to change this so i can upload to different pages without the photo going to them all. please help

      thanks in advance for any1 who is smart enough to come up with the answer.

      ( Reply )
    76. PG

      xtc2xl July 7th

      nice effect on vid, but for some reason just full of bugs when trying the source. good intro anyhow thnx

      ( Reply )
    77. PG

      Thom July 17th

      hi would really appreciate it if someone could help, if people still replying.

      i have added a title field to the form which works and want to add 2 more for Country and Album name. What i would like is that when the image is uploaded instead of going just to the images folder the image goes to

      images/country/album_name/fullsized or tn – in response to what was inputed in the form

      and if the folder does not exist to create it – mkdir

      if anyone could help you would solve all my problems and i can get my site finished

      ( Reply )
      1. PG

        Thom July 20th

        was having problems until i realised needed to use $_REQUEST to grab the form input. finally. wish i wasn’t a newbie to php, takes so long to figure things out, but getting there.

        ( Reply )
    78. PG

      ibrahim benzer July 30th

      jeff i dont think it s a good idea to check for .jpg or .png in file name… the filename can be code.jpg.php
      why dont u check for the last “.” in the file name and control the filetype by that?

      ( Reply )
    79. PG

      BBQ September 11th

      anyone got this thing working correctly ? I still can’t manage to get the images uploaded and thumbnails created :/

      ( Reply )
    80. PG

      Spadez September 14th

      Great tutorial, but can the source code please be revised, as a lot of people are reporting the same errors out of the box and it isnt very helpful for newbies to be given code with errors, it takes us so long to figure out whats wrong.

      ( Reply )
    81. PG

      Peter September 14th

      got it running but but when i upload an image it write to the database but does not upload the inage to the image folder not the thumb folder. I had a look at the code and i cant find any reference to the uploadPhoto.php file ..so should this not be referenced for it to upload to the files???

      ( Reply )
      1. PG

        Arkad September 21st

        I would suggest you check the config file ‘$path_to_thumbs_directory = ‘images/tn/’;’ see it that folder exists

        otherwise it might be the sql code or database structure, hard to tell without being able to see the code

        ..good luck

        ( Reply )
    82. PG

      Arkad September 18th

      Shot for the tutorial

      I’m pretty new to all this so I not sure if I am just missing something but it seems to me that in the code ( downloaded “source” ) in the functions.php page you have declared a variable that doesn’t exist anywhere.

      $mysqli_error – line 9

      although it is obvious that this is not a variable but a php defined function.
      just wondering if you do that on purpose

      I quite enjoy debugging it, I just figured you seem way to competent to make such a simple error. – or is used as a variable later or something?

      Not sure if anyone has pick up on this. Not a chance I am doing to read through all of the comments. will be very suprised if anyone even bothers to scroll down this far.. shouldn’t the most recent comments be displayed first?

      ORDER BY timestamp?

      very cool site though – like the random text thing you got going next to your logo on the footer
      “I don’t know how to put this but i’m kind of a big deal”

      ( Reply )
    83. PG

      Bozidar September 24th

      I need help to implement this php code into my html page…i succesfuly tested index.php on my wamp server but when i tried to implemnent code from index.php to my html he won’t create thumbs and show me this

      Please enter a description for your photo. ‘; if($filename == ” || !preg_match(‘/[.](jpg)|(gif)|(png)|(jpeg)$/’, $filename)) $error['no_file'] = ‘

      Please select an image, dummy!
      ‘; if(!$error) { move_uploaded_file($source, $target); $q = “INSERT into photo(description, src, tn_src) VALUES(‘$description’, ‘$src’, ‘$tn_src’)”; $result = $mysqli->query($q) or die(mysqli_error($mysqli)); if($result) { echo “Success! Your file has been uploaded”; } createThumbnail($filename); } // end preg_match } ?>

      i am new in web programing

      ( Reply )
    84. PG

      David October 7th

      Warning: imagecreatefromjpeg(images/chroma.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/u0051213827/public_html/blog/photo/functions.php on line 74

      Warning: imagesx(): supplied argument is not a valid Image resource in /home/u0051213827/public_html/blog/photo/functions.php on line 81

      Warning: imagesy(): supplied argument is not a valid Image resource in /home/u0051213827/public_html/blog/photo/functions.php on line 82

      Warning: Division by zero in /home/u0051213827/public_html/blog/photo/functions.php on line 85

      Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/u0051213827/public_html/blog/photo/functions.php on line 87

      Warning: imagecopyresized(): supplied argument is not a valid Image resource in /home/u0051213827/public_html/blog/photo/functions.php on line 89

      Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/u0051213827/public_html/blog/photo/functions.php on line 97

      Warning: Cannot modify header information – headers already sent by (output started at /home/u0051213827/public_html/blog/photo/index.php:32) in /home/u0051213827/public_html/blog/photo/functions.php on line 99

      any ideas? i dont geht it script dont work for me =( pls help

      ( Reply )
    85. PG

      Huroman November 4th

      The code seems awesome BUT don’t try to make it real, it has a lot of BUGS.

      1. It has problem with upload images (sometimes don’t load the image and thumbnail, Why? We do not know)

      2. “Delete function” delete the image from SQL but don’t eliminate the image in the folder who contains the image and the thumbnail.

      3. This example is good to understand how an admin works, but it’s far away to be useful.

      ( Reply )
    1. Arrow
      Gravatar

      Your Name
      November 4th