Topic: PHP Photo Album (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=28972" title="Pages that link to Topic: PHP Photo Album (Page 1 of 1)" rel="nofollow" >Topic: PHP Photo Album <span class="small">(Page 1 of 1)</span>\

 
Gwynaveir
Obsessive-Compulsive (I) Inmate

From: Australia
Insane since: May 2006

IP logged posted posted 02-19-2007 07:13 Edit Quote

I just can't seem to get my head around PHP. I've been trying to learn it for a couple of weeks now and my brain just fuzzes over. In any case, I was following this tutorial: http://www.zend.com/zend/trick/tricks-jan-2003.php
and I've done something wrong and I can't find it!

My pages:

http://reference-desk.net/gallery/addpic.php
http://reference-desk.net/gallery/view.php
http://reference-desk.net/gallery/big.php

And the code for my pages:

Config:

code:
<?php
#thumbnail width and height
define("THUMBNAIL_WIDTH", "100");
define("THUMBNAIL_HEIGHT", "75");

# maximum number of photos displayed on an album page
define("MAX_DISPLAYED_PHOTOS","36");

# The image directory's relative and absolute path
define("IMAGE_PATH", "images");
define("ABSOLUTE_PATH","/reference-desk.net/gallery/images");

# Connect to the MySQL server and select the database
$connection = mysql_pconnect(Passwords removed by TP);
$db = mysql_select_db("green"); 

function add_photo($photoFileName, $title, $description)
{
     $query = "INSERT INTO photo SET photoID=NULL,   
               photoFileName='$photoFileName',
               title='$title',
               description='$description'";
     $result = mysql_query($query);
     return $result;
} 

function retrieve_album_page($offset) 
{
     $rows = MAX_DISPLAYED_PHOTOS;

     $query = "SELECT photoID, photoFileName, title 
               FROM photo ORDER BY photoID 
               LIMIT $offset, $rows";

     $result = mysql_query($query);

     return $result;
} 

function next_page($offset) 
{
     $photoCount = retrieve_photo_count();

     if ($offset < $photoCount) {
          echo "<a href='view.php?offset=$offset'>Next Page</a> >>";
     } else {
          echo "Next Page >>";  
     }
} 

function retrieve_photo_count()
{

  $countQuery = "SELECT count(photoID)
                 AS photoCount FROM photo";

  $countResult = mysql_query($countQuery);

  return mysql_result($countResult,0,"photoCount");

} 

function previous_page($offset, $totalRows) 
{
     if ($offset - MAX_DISPLAYED_PHOTOS > 0) 
     {
          $offset = $offset - $totalRows - MAX_DISPLAYED_PHOTOS;
          echo "<< <a href='view.php?offset=$offset'>Previous Page</a>";
     } else {
          echo "<< Previous Page";  
     }
} 

function retrieve_photo($photoID) 
{
     $query = "SELECT photoID, photoFileName, title,
         description FROM photo WHERE photoID='$photoID'";

     $result = mysql_query($query);

     return $result;
} 


AddPic:

<?php
include "config.php";

// Use Heredoc syntax to format the XHTML form
$addPhotoForm = <<< addPhotoForm
<p>Add a photo to the album</p>
<form action="addpic.php" 
enctype="multipart/form-data" method="post">
     <p>
          Photo:<br />
          <input name="photo" type="file" />
     </p>

     <p>
          Descriptive Title:<br />
          <input type="text" name="title" 
          size="40" maxlength="80" value="" />
     </p>

     <p>
          Description:<br />
          <textarea name="description" 
          rows="3" cols="40"></textarea>
     </p>

     <p>
          <input type="submit" value="Add photo!" />
     </p>
</form>
addPhotoForm;

// If the user has submitted a file for uploading.
if (is_uploaded_file($_FILES['photo']['tmp_name'])) {
    # Add the photo to the MySQL database
    add_photo($_FILES['photo']['name'], $_POST['title'], 
    $_POST['description']) or die("couldnt add photo");
    # Move the photo from the temp directory to
    # the images directory.
    move_uploaded_file($_FILES['photo']['tmp_name'],
    ABSOLUTE_PATH.$_FILES['photo']['name']);

    echo "<p>The photo was successfully uploaded .</p>";

}
// display the form on every page instance
echo $addPhotoForm;
?>


View:

<?php
include "config.php";

$offset = isset($_GET['offset']) ? $_GET['offset'] : 0;   

$offsetOriginal = $offset;

$photoQueryResult = retrieve_album_page($offset);

$totalRows = mysql_numrows($photoQueryResult);

while ($row = mysql_fetch_array($photoQueryResult)) 
{

   $photoID = $row['photoID'];
   $photoFileName = $row['photoFileName'];
   $title = $row['title'];

   echo "<div class='float'><a href='viewphoto.php?photoID=$photoID&offset=$offsetOriginal'>
<img src='".IMAGE_PATH."/$photoFileName' width='".THUMBNAIL_HEIGHT."' height='".THUMBNAIL_HEIGHT."' border='0' alt='$title' /></a><br /><p>$title</p></div>";

     $offset++;

}

echo "<div><p>"; 
echo previous_page($offset, $totalRows); 
echo "<br />";
echo next_page($offset);
echo "</p></div>";
?>

</body>
</html>


Big:

<?php
include "config.php";

// Display the photo
$photoQueryResult = retrieve_photo($_GET[photoID]);

list($photoID, $photoFileName, $title, $description) = mysql_fetch_array($photoQueryResult);

// Retrieve the image size.
$size = getimagesize(IMAGE_PATH."/$photoFileName");

echo "<div class='float'><img src='".IMAGE_PATH."/$photoFileName' $size[3] alt='$title' />
<br /><p>$title<br />$description</p>
<p><a href='view.php?offset=$_GET[offset]'>Back</a></p></div>";
?>
</body>
</html>


The World is Made in Desperation, and I am a Desolate Spirit - The Misery


Edit TP: added code tags, removed passwords.

(Edited by Tyberius Prime on 02-19-2007 17:25)

rukuartic
Bipolar (III) Inmate

From: Underneath a mountain of blankets.
Insane since: Jan 2007

IP logged posted posted 02-19-2007 14:23 Edit Quote

It might help if you tell us what exactly goes wrong.

Also as a note, you shouldn't put your password up there, even if your account is limited to localhost logins only.

rukuartic@halflght:~/$ whatis life
life: nothing appropriate.

Gwynaveir
Obsessive-Compulsive (I) Inmate

From: Australia
Insane since: May 2006

IP logged posted posted 02-19-2007 21:41 Edit Quote

Eep, just goes to show you how much my brain DESPISES me :-P Cheers.

Well, so far, it won't upload any pictures (uploading goes to screen saying "couldnt upload picture") and the View and Big pages both have errors to do with something thats undefined.

The World is Made in Desperation, and I am a Desolate Spirit - The Misery



Post Reply
 
Your User Name:
Your Password:
Login Options: Remember Me On This Computer
 
Your Text:
Loading...
Options: Show Signature
Enable Slimies
Enable Linkwords

« BackwardsOnwards »

Show Forum Drop Down Menu