Build An Automated PHP Gallery System In Minutes

Basically if you write over the “<!-- Add your site header here –>
HTML DESIGN-start” You will have no problems inserting your code. You have to use absolute addresses to include files in different directories (http://www.yourcode.cim/includes/yourcode.php). I thought that it was a faulty design until I tried to brute force it myself and saw where it ended up.

I don’t know if that will solve your header problem, but it should, all html and php will come after the header has already parsed.

I’m actually seeing this when I do a view source…


<meta name="keywords" content="" />
<meta name="description" content="" />
<TITLE>RenikDelan's Site</TITLE>
<? include("http://www.renikdelan.com/includes/header.php") ?>
<div class="content">

And when I try and add in the footer? That just bones the whole thing into an exception error…

If anyone wants to give me a design.inc page with a header and footer that has a php include, itd be a HUGE help…

Just want to say your gallery article is useful, therefore I don’t use it.

Also renikdelan, the begining of your index.php file calls out to include(design.inc.php) twice, for some reason it will only work if this remains so. Make sure that you keep both of those lines.

You have to place all of your <style> code within the <<<__HTML_END and __HTML_END; area.

I have just copied whole code of page 2(preupload.php) of this tutorial, but didn’t get the same look as screenshot right below the code on page 2 (preupload.php) of tutorial. Secondly don’t understand what those codes meant “<<<__HTML_END"and”__HTML_END;", I have attached the code below, please let me know if I am wrong, this is the url of the tutorial :http://www.sitepoint.com/article/php-gallery-system-minutes/2, thanks bunch!!

<?php 
 include 'config.inc.php'; 

 // initialization 
 $photo_upload_fields = ''; 
 $counter = 1; 

 // If we want more fields, then use, preupload.php?number_of_fields=20 
 $number_of_fields = (isset($_GET['number_of_fields'])) ? 
   (int)($_GET['number_of_fields']) : 5; 

 // Firstly Lets build the Category List 
 $result = mysql_query('SELECT category_id,category_name FROM gallery_category'); 
 while($row = mysql_fetch_array($result)) { 
   $photo_category_list .= <<<__HTML_END 
<option value="$row[0]">$row[1]</option>\
 
__HTML_END; 
 } 
 mysql_free_result( $result );   

 // Lets build the Image Uploading fields 
 while($counter <= $number_of_fields) { 
   $photo_upload_fields .= <<<__HTML_END 
<tr><td> 
 Photo {$counter}: 
 <input name="photo_filename[]" 
type="file" /> 
</td></tr> 
<tr><td> 
 Caption: 
 <textarea name="photo_caption[]" cols="30" 
   rows="1"></textarea> 
</td></tr> 
__HTML_END; 
   $counter++; 
 } 

 // Final Output 
 echo <<<__HTML_END 
<html> 
<head> 
<title>Lets upload Photos</title> 
</head> 
<body> 
<form enctype="multipart/form-data" 
 action="upload.php" method="post" 
 name="upload_form"> 
 <table width="90%" border="0" 
   align="center" style="width: 90%;"> 
   <tr><td> 
     Select Category 
     <select name="category"> 
     $photo_category_list 
     </select> 
   </td></tr> 
   <!—Insert the image fields here --> 
   $photo_upload_fields 
   <tr><td> 
     <input type="submit" name="submit" 
       value="Add Photos" /> 
   </td></tr> 
 </table> 
</form> 
</body> 
</html> 
__HTML_END; 
?> 

Do you have a trouble for showing the upload form as the same as screen shot in the tutorial(preupload.php) that I mentioned? If you don’t, can you let me know how to understand the codes <<<__HTML_END"and"__HTML_END;". I don’t understand them. Do I need to create a header.php and footer.php individually to be able to display preupload.php correctly?

Thanks.

Excellent tutorial: can somebody tell me though, how do I alter the code so that regardless of the uploaded file type (as long as it is GD version compatible), the sytem creates and resizes the original image into a jpeg and creates the thumbnail as a gif??

Thanks.

by the way… I’m referring to the tutorial at: http://www.sitepoint.com/article/php-gallery-system-minutes

I have the same problem and posted the question, so far no one answer our problem, well, all we need to do is that keep in faith in this forum.

I have the same problem and posted the question, so far no one answer our problem, well, all we need to do is that keep in faith in this forum.

you could have a form with so many feilds (say 20) for the user to upload there photos. then place these files into a temporay folder awaiting approval from you.

this will aquire a table in the database for listing new awaiting approvals.

doing it your way will take longer. the way above can also check the file size, type, width and height. this will help in the before uploading, then you can then check if the photo is then suitable either by a thumbnail or a full size view.

spence

sorry for not replying back sooner, we’ve all been busy.

anyway, those tags “<<<__HTML_END"and”__HTML_END;" are another way of doing " or a '.

still not clear? :confused:

here’s an example of the code changed to way i’m going on about:


  <?php 
    include 'config.inc.php'; 
   
    // initialization 
    $photo_upload_fields = ''; 
    $counter = 1; 
   
    // If we want more fields, then use, preupload.php?number_of_fields=20 
    $number_of_fields = (isset($_GET['number_of_fields'])) ? 
      (int)($_GET['number_of_fields']) : 5; 
   
    // Firstly Lets build the Category List 
    $result = mysql_query('SELECT category_id,category_name FROM gallery_category'); 
    while($row = mysql_fetch_array($result)) { 
      $photo_category_list .= '<option value="$row[0]">$row[1]</option>\
'; 
    } 
    mysql_free_result( $result );   
   
    // Lets build the Image Uploading fields 
    while($counter <= $number_of_fields) { 
      $photo_upload_fields .= ' 
  <tr><td> 
    Photo {$counter}: 
    <input name="photo_filename[]" 
  type="file" /> 
  </td></tr> 
  <tr><td> 
    Caption: 
    <textarea name="photo_caption[]" cols="30" 
      rows="1"></textarea> 
  </td></tr>'; 
      $counter++; 
    } 
   
    // Final Output 
    echo '<html> 
  <head> 
  <title>Lets upload Photos</title> 
  </head> 
  <body> 
  <form enctype="multipart/form-data" 
    action="upload.php" method="post" 
    name="upload_form"> 
    <table width="90%" border="0" 
      align="center" style="width: 90%;"> 
      <tr><td> 
   	 Select Category 
   	 <select name="category"> 
   	 $photo_category_list 
   	 </select> 
      </td></tr> 
      <!—Insert the image fields here --> 
      $photo_upload_fields 
      <tr><td> 
   	 <input type="submit" name="submit" 
   	   value="Add Photos" /> 
      </td></tr> 
    </table> 
  </form> 
  </body> 
  </html>'; 
  ?>
  

getting it now? :slight_smile:

here’s a small snippet of the code:

the orig:


  $photo_category_list .= <<<__HTML_END 
  <option value="$row[0]">$row[1]</option>\
 
  __HTML_END;
  

the changed example:


  $photo_category_list .= '<option value="$row[0]">$row[1]</option>\
';
  

i personally prefer the changed example above, to me it makes it easy to understand and read. others will like the other method of using the html tags “<<<__HTML_END”, etc…

the problem with the method that i like using is you may have to do something like the code below to get the code to work, only if there’s an error message appearing in the web browser:


 <option value="'.$row[0].'">'.$row[1].'</option>
 

as for the other question:

Do I need to create a header.php and footer.php individually to be able to display preupload.php correctly?

you will need to create a header.php and footer.php to display the top and bottom of each page.

the preupload.php goes inbetween the header and footer then placed into the index page through the web browser.

spence

could you post your code so we can view what you’ve done?

ta!

spence

This is a great script no doubt. However, if we need to upload hundreds of photos, this may not be the most suitable one. I was looking for something that will allow me to do so. As a solution, I was thinking to help users to upload photos in a zip file which will then be unzipped and (images) resized in the server itself … any solution?
thanks.

Thanks so much. But I’ve got this error when I called it in browser:Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:\Inetpub\wwwroot\photoGallery\config.inc.php on line 2

Warning: mysql_select_db(): Access denied for user ‘ODBC’@‘localhost’ (using password: NO) in C:\Inetpub\wwwroot\photoGallery\config.inc.php on line 3

Warning: mysql_select_db(): A link to the server could not be established in C:\Inetpub\wwwroot\photoGallery\config.inc.php on line 3
Could not select database Here is the PHP code that I just copied it in page 1 making config.php file:

<?php 
$mysql_link = mysql_connect('localhost', 'root', 'root'); 
mysql_select_db('myphotogallery') or die('Could not select database'); 
$images_dir = 'photos'; 
?>

try this:


 <?php
 $mysql_link = mysql_connect('localhost', 'root', 'root')
 or die ('I cannot connect to the database because: ' . mysql_error());
 mysql_select_db('myphotogallery');
 
 $images_dir = 'photos';
 ?> 
 

Tried, still got this Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:\Inetpub\wwwroot\photoGallery\config.inc.php on line 2. Don’t know why this tutorial has so many unclear definition, that created so much confusion for people.

are you trying to connect to a mysql database on the internet? or is it on your pc?

for folk who are having problems connecting to their mysql database locally click here for a fix.

I was trying to connect to my local testing server on my local PC. And the problem is not Mysql Socket, it shows that the problem of config.inc.php file that this tutorial provided on the first page.

Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:\Inetpub\wwwroot\photoGallery\config.inc.php on line 2

Fatal error: Call to undefined function: mysql_erro() in C:\Inetpub\wwwroot\photoGallery\config.inc.php on line 2

This is the config.inc.php file code:

<?php 
$mysql_link = mysql_connect('localhost', 'root', 'root')or die ('I cannot connect to the database because:'.mysql_erro());
mysql_select_db('myphotogallery'); 

$images_dir = 'photos'; 
?>