Picturegallery driller
Hej alle....Jeg sider med et galleri hvor man kan uploade billeder i, Mit pro er nu at den kommer med en fejl hele tiden.
Fejl:
Warning: Unable to create '/var/www/hotels/1go/nokia3510i/html/albums/albums/userpics/bob_hund.jpg': No such file or directory in /var/www/hotels/1go/nokia3510i/html/functions.php on line 623
<<Min kode i functions.php>>
<?
/*************************************************
* PHPhotoalbum v0.4
* by: Henning Støverud
* e-mail: henning@stoverud.com
* URL: http://www.stoverud.com/PHPhotoalbum/
*************************************************/
require("config.inc.php");
// Function for writing a pageheader
function pageheader($section)
{
global $config;
echo "<html>\n";
echo "<head>\n";
echo " <title>PHPhotoalbum - $section</title>\n";
echo " <link rel=\"stylesheet\" href=\"style.css\">\n";
?>
<script language="JavaScript" type="text/javascript">
<!--
function go(){
if (document.jumpto.pids.options[document.jumpto.pids.selectedIndex].value != "none") {
location = document.jumpto.pids.options[document.jumpto.pids.selectedIndex].value;
}
}
function confirmAlbum(stuffid)
{
var is_confirmed = confirm("Are you sure you want to DELETE this album? (id: " + stuffid + ") \n\nWARNING: All the pictures and comments in this album will \nalso be deleted!");
if (is_confirmed) {
// Do nothing...
}
return is_confirmed;
}
function confirmPicture(stuffid)
{
var is_confirmed = confirm("Are you sure you want to DELETE this picture? (id: " + stuffid + ") \nComments will also be deleted.");
if (is_confirmed) {
// Do nothing...
}
return is_confirmed;
}
function confirmComment(stuffid)
{
var is_confirmed = confirm("Are you sure you want to DELETE this comment? (id: " + stuffid + ")");
if (is_confirmed) {
// Do nothing...
}
return is_confirmed;
}
//-->
</script>
<?php
echo "</head>\n";
echo "<body>\n";
}
// Function for writing a pagefooter
function pagefooter($width)
{
global $config;
$width2 = $width-2;
echo "
<table width=\"$width\" align=\"center\">
<td bgcolor=\"#000000\" width=\"$width\">
<table bgcolor=\"#f9f9f9\" width=\"$width2\">
<tr>
<td>
<div class=\"footer\" align=\"right\">
<a href=\"http://www.stoverud.com/PHPhotoalbum/\">PHPhotoalbum</a> v$config[ver] by ";
writeEmail(); // Write e-mail address
echo " </div>
</td>
</tr>
</table>
</td>
</table>
</body></html>";
}
// Writes cryptic e-mail address
function writeEmail()
{
?>
<script type="text/javascript">
<!--
var first = 'ma';
var second = 'il';
var third = 'to:';
var address = 'henning';
var domain = 'stoverud.com';
document.write('<a href="');
document.write(first+second+third);
document.write(address);
document.write('@');
document.write(domain);
document.write('" title="">');
document.write('Henning Støverud<\/a>');
// -->
</script>
<?
}
// Function for DB connection
function db_connect()
{
global $config;
$result = @mysql_pconnect($config['dbserver'], $config['dbuser'], $config['dbpass']);
if (!$result)
return false;
if (!mysql_select_db($config['dbname']))
return false;
return $result;
}
// Function for convert DB-result to array
function db_result_to_array($result)
{
$res_array = array();
for ($count=0; $row = @mysql_fetch_array($result); $count++)
$res_array[$count] = $row;
return $res_array;
}
// Prints thumbnails of all pictures in an album
function thumbnails($album, $thumbcols)
{
global $config, $logged_in;
if(!isset($album))
{
echo "You have to choose an album.<br><br>\n";
echo "<b>- <a href=\"index.php\">List of albums</a></b>";
exit;
}
$conn = db_connect();
$result = mysql_query("SELECT * from $config[TABLE_PICTURES] WHERE aid='$album'");
$count = mysql_num_rows($result);
echo "<div style=\"thumbnails\" align=\"right\"><h3>Album $album<hr></h3></div>\n";
echo "<tr>\n";
$i = 1; // Col counter starts at 1.
// Displays thumbs if the query returns a result.
if($count > 0){
while($row = mysql_fetch_array($result))
{
$comments = get_comments($row["pid"]);
$ant_cmts = count($comments);
$imagesize = getImageSize("$config[fullpath]"."$row[filepath]thumb_$row[filename]");
echo "<td valign=\"top\" class=\"thumbnails\" align=\"center\">";
echo "<a href=\"displayimage.php?pid=".$row["pid"]."\" class=\"thumbnails\">";
echo "<img src=\"$config[albumdir]".$row["filepath"]."thumb_".$row["filename"]."\" $imagesize[3] border=\"1\"></a>";
if($ant_cmts > 0)
echo "<br><div class=\"ant_cmts\">$ant_cmts comment(s)</div>";
if($logged_in)
show_picturemenu_small($row["pid"]);
echo "</td>\n";
if($i==$thumbcols) // Checks with config.inc.php how many cols are set..
{
echo "</tr>\n";
echo "<tr>\n";
$i = 1;
}
else
{
$i++;
}
}
}
else {
echo "<td valign=\"top\" class=\"thumbnails\">";
echo "<b>Album $album does not contain any images.<br>\n";
echo "<li><a href=\"admin.php?album=$album\">Add images</a><br>\n";
echo "<li><a href=\"index.php\">Back to album index</a><br>\n";
echo "</td>\n";
}
}
// Prints the total number of pictures in the database
function countpics()
{
global $config;
$connection = db_connect();
$result = mysql_query("SELECT * from $config[TABLE_PICTURES]");
$count = MYSQL_NUMROWS($result);
echo $count;
mysql_close($connection);
}
// Prints the total number of pictures in a certain album.
// You have to specify an album. (aid).
function countalbumpics($album)
{
global $config;
$connection = db_connect();
$result = mysql_query("SELECT * from $config[TABLE_PICTURES] where aid=$album");
$count = mysql_num_rows($result);
echo $count;
}
// Prints the total number of comments in the database
function countcomments()
{
global $config;
$connection = db_connect();
$result = mysql_query("SELECT * from $config[TABLE_COMMENTS]");
$count = mysql_num_rows($result);
echo $count;
}
// Prints the total number of comments for a certain picture
function countpiccomments($pid)
{
global $config;
$connection = db_connect();
$result = mysql_query("SELECT * from $config[TABLE_COMMENTS] where pid=$pid");
$count = mysql_num_rows($result);
echo $count;
}
// Prints the total number of picviews
function countpicviews()
{
global $config;
$connection = db_connect();
$result = mysql_query("SELECT sum(hits) from $config[TABLE_PICTURES]");
$count = mysql_result($result, 0);
echo $count;
}
// Displays comments for each picture
function showcomments($pid)
{
global $config;
global $PHP_SELF, $logged_in;
$connection = db_connect();
$result = mysql_query("SELECT * from $config[TABLE_COMMENTS] where pid=$pid ORDER by msg_date asc");
echo "<table width=\"100%\" cellspacing=0>";
while($row = mysql_fetch_array($result))
{
echo "<tr><td bgcolor=\"$config[color_comment_heading]\"><b>".$row["msg_subject"]."</b>"." <font size=\"-2\" color=\"#5F5F5F\">[". $row["msg_date"]."]</font></td>";
echo "<td bgcolor=\"$config[color_comment_heading]\" align=\"right\">";
if($logged_in)
show_commentsmenu($row['msg_id']);
echo "</td";
echo "</tr>\n";
echo "<tr><td colspan=\"2\" bgcolor=\"$config[color_comment_body]\">".$row["msg_body"]."</td></tr>\n";
echo "<tr><td colspan=\"2\"><img src=\"$webdir/images/spacer.gif\" width=\"1\" height=\"4\"></td></tr>\n";
}
echo "</table>";
// REMOVES ADD_COMMENT link from addcomment form.
if ($PHP_SELF != "$config[webdir]"."addcomment.php"){
echo "<b><a href=\"addcomment.php?pid=$pid#comment\">Add comment</a></b>";
}
}
// Displays comments for each picture
function get_comments($pid)
{
global $config;
global $PHP_SELF;
$connection = db_connect();
$result = mysql_query("SELECT * from $config[TABLE_COMMENTS] where pid=$pid ORDER by msg_date asc");
while($row = mysql_fetch_array($result))
{
$comment[$i++] = $row[0];
}
return $comment;
}
// This is the most complex function
// Displays a picture with navigation and picture-info
function showpicture($pid)
{
addhit($pid); // Hit counter
global $config;
global $hits, $maxpid, $album, $row, $current_pic;
$connection = db_connect();
$result = mysql_query("SELECT * from $config[TABLE_PICTURES] where pid='$pid'");
$row = mysql_fetch_array($result);
$navresult = mysql_query("SELECT pid from $config[TABLE_PICTURES] where aid='$row[aid]'");
$maxpid = mysql_num_rows($navresult);
// Makes an array with all valid pids.
// First key is 1 not 0...
$nav_array = array();
$i=1;
while($query_data = mysql_fetch_array($navresult))
{
$nav_array[$i] = $query_data[pid];
$i++;
}
// Prints all values in $nav_array
while($array_cell = each($nav_array))
{
if($array_cell['value'] == $pid)
{
$current_pic = $array_cell['key'];
}
}
echo "<div class=\"navmenu_pic\" align=\"center\">\n";
echo "<a href=\"$config[albumdir]$row[filepath]$row[filename]\" border=\"0\">";
if(file_exists("$config[fullpath]$row[filepath]"."normal_"."$row[filename]")) {
$picturename = "$config[albumdir]$row[filepath]"."normal_"."$row[filename]";
$imagesize = getImageSize("$config[fullpath]$row[filepath]"."normal_$row[filename]");
}
else {
$picturename = "$config[albumdir]$row[filepath]$row[filename]";
$imagesize = getImageSize("$config[fullpath]$row[filepath]$row[filename]");
}
echo "<img src=\"$picturename\" $imagesize[3] border=\"1\"></a><br>\n";
echo "<img src=\"$webdir"."images/spacer.gif\" width=\"1\" height=\"2\"><br>";
// echo "<a href=\"$PHP_SELF?pid=$prev\" class=\"navmenu_pic\"><<prev</a> |pic ";
echo "pic ";
listallpids();
// echo " / $maxpid | <a href=\"displayimage?pid=$next_pid\" class=\"navmenu_pic\">next>></a><br>\n";
echo " of $maxpid";
echo "<br>\n";
echo "<a href=\"thumbnails.php?album=$row[aid]\" class=\"navmenu\"><< back to thumbnails</a><br>\n";
echo "</div>\n";
// Pictureinfo
echo "<div class=\"pictureinfo\">\n";
echo "<hr>";
echo "Picture ID: $row[pid]<br>\n";
echo "Album: $row[aid]<br>\n";
echo "filename: $row[filename]<br>\n";
echo "Dimentions: $row[pwidth] x $row[pheight]<br>\n";
echo "Displayed: $hits times\n";
echo "<hr>\n";
echo "</div>\n";
}
//Prints the top-navigation menu
function navmenu($width)
{
global $logged_in, $config;
$width2 = $width-2;
echo" <table width=\"$width\" align=\"center\">
<td bgcolor=\"#000000\" width=\"$width\">
<table bgcolor=\"$config[color_nav]\" width=\"$width2\">
<tr>
<td>";
echo "<div class=\"navmenu\">";
echo "<a href=\"index.php\" class=\"navmenu\"> << ALBUMS</a> | <a href=\"admin.php\" class=\"navmenu\">ADMIN</a> | <a href=\"statistics.php\" class=\"navmenu\">STATISTICS</a> | <a href=\"upload.php\" class=\"navmenu\">UPLOAD PICTURE</a> | ";
if($logged_in)
echo "<a href=\"logout.php\" class=\"navmenu\">LOGOUT</a>";
else
echo "<a href=\"login.php\" class=\"navmenu\">LOGIN</a>";
echo "<br>\n";
echo "</div>";
echo "</td>
</tr>
</table>
</td>
</table>";
}
// Adds 1 everytime a picture is viewed.
function addhit($pid)
{
global $hits;
global $config;
$connection = db_connect();
$result = mysql_query("SELECT hits from $config[TABLE_PICTURES] where pid='$pid'");
$query_data = mysql_fetch_row($result);
$hits = $query_data[0];
$hits++;
$insert = mysql_query("UPDATE $config[TABLE_PICTURES] SET hits='$hits' WHERE pid='$pid'");
}
// Top x list
function toplist($length, $textlength)
{
global $config;
$connection = db_connect();
$result = mysql_query("SELECT pid, filename, hits from $config[TABLE_PICTURES] order by hits desc limit $length");
$i=1;
while($query_data = mysql_fetch_row($result))
{
$pid = $query_data[0];
$filename = $query_data[1];
$hits = $query_data[2];
echo "$i. <a href=\"displayimage.php?pid=$pid\">". substr($filename, 0,$textlength) ."</a> ($hits hits)";
echo "<br>";
$i++;
}
}
// Shows last comments
function lastcomments($length)
{
global $config;
$connection = db_connect();
$result = mysql_query("SELECT pid, msg_subject, msg_date, msg_body from $config[TABLE_COMMENTS] order by msg_date desc limit $length");
if(mysql_num_rows($result) <= 0){
echo "none..<br>";
return false;
}
$i=1;
while($query_data = mysql_fetch_row($result))
{
$pid = $query_data[0];
$filename = $query_data[1];
if($query_data[1] != "")
$filename = $query_data[1];
else
$filename = $query_data[3];
$hits = $query_data[2];
echo "<a href=\"displayimage.php?pid=$pid\">". substr($filename, 0,25) ."</a> ";
echo "<br>";
$i++;
}
}
// Shows last uploads
function lastuploads($length)
{
global $config;
$connection = db_connect();
$result = mysql_query("SELECT pid, filename FROM $config[TABLE_PICTURES] ORDER BY pid DESC LIMIT $length");
if(mysql_num_rows($result) <= 0) {
echo "none..";
return false;
}
$i=1;
while($query_data = mysql_fetch_row($result))
{
$pid = $query_data[0];
$filename = $query_data[1];
echo "<a href=\"displayimage.php?pid=$pid\">". substr($filename, 0,25) ."</a> ";
echo "<br>";
$i++;
}
}
// It's listing all the pids and picturenumber and puts them in a select-box
function listallpids()
{
global $maxpid, $color_nav, $color_main, $row, $current_pic;
global $config;
$connection = db_connect();
$result2 = mysql_query("SELECT pid from $config[TABLE_PICTURES] where aid=$row[aid]");
$count = mysql_num_rows($result2);
$i=1;
echo "<select name=\"pids\" onchange=\"go()\" STYLE=\"FONT-FAMILY:VERDANA, GENEVA, ARIAL, HELVETICA; FONT-SIZE:9px; BORDER-STYLE : groove;\">\n";
while($row2 = mysql_fetch_array($result2))
{
if($i == $current_pic)
{
echo "<option value=\"displayimage?pid=".$row2["pid"]."\" selected>$i</option>\n";
}
else
{
echo "<option value=\"?show=$webdir/displayimage&pid=".$row2["pid"]."\">$i</option>\n";
}
$i++;
}
echo "</select>\n";
}
// List all albums
function albums()
{
global $config, $logged_in;
$connection = db_connect();
if(!$connection) {
echo "Could not connect to the database. Check your config.inc.php";
exit;
}
$result = mysql_query("SELECT * from $config[TABLE_ALBUMS] order by aid asc");
if(!$result){
echo "Could not find any data. Make sure you've created a database and tables from album.sql";
exit;
}
$nrOfAlbums = mysql_num_rows($result);
if($nrOfAlbums <= 0){
echo "No albums avaliable.<br>";
echo "<a href=\"admin.php\">Click here</a> to create one.";
}
while($row = mysql_fetch_array($result))
{
$result2 = mysql_query("SELECT * from $config[TABLE_PICTURES] where aid=$row[aid]");
$picture = mysql_fetch_array($result2);
echo "<tr><td valign=\"top\" class=\"thumbnails\">";
echo "<a href=\"thumbnails.php?album=".$row["aid"]."\" class=\"albums\">Album ";
echo $row["aid"];
echo "<br>";
// Count the number of pictures for the actual album
$count = mysql_num_rows($result2);
// Inserts a small thumbnail if the album contains 1 or more images
if($count > 0){
echo "<img src=\"$config[albumdir]$picture[2]"."thumb_$picture[3]\" width=\"54\" height=\"30\" border=\"1\"></a>";
}else {
echo "<img src=\"images/nopics.gif\" width=\"54\" height=\"30\" border=\"1\"></a>";
}
echo "</td><td valign=\"bottom\" class=\"thumbnails_info\">";
echo "<b>AID</b>:"." ".$row["aid"];
echo "<br>\n";
echo "<b>Pics</b>: ";
echo $count;
echo "<br>\n";
echo "<b>Desc</b>:"." ". $row["description"];
if($logged_in)
show_albummenu($row['aid']);
echo "</td></tr>\n";
}
}
// Lists all albums in a dropdown-menu.
function listallalbums($album)
{
global $config;
$connection = db_connect();
$result2 = mysql_query("SELECT * FROM $config[TABLE_ALBUMS] ORDER BY aid ASC");
echo "<select name=\"album\" STYLE=\"WIDTH: 120; FONT-FAMILY:VERDANA, GENEVA, ARIAL, HELVETICA; FONT-SIZE:9px; BORDER-STYLE : groove;\">\n";
while($row2 = mysql_fetch_array($result2))
{
if($row2['aid'] == $album)
$selected = "SELECTED";
else
$selected = "";
echo "<option value=\"".$row2["aid"]."\" $selected>".$row2["aid"]." - ".$row2["description"]."</option>\n";
$i++;
}
echo "</select>\n";
}
// Function for imageresizeing. Used to make thumbnails
function album_resizeImage($src_file, $dest_file, $newWidth, $method)
{
// find the image size
$imginfo = @getimagesize($src_file);
if ($imginfo == NULL)
return false;
// height/width
$srcWidth = $imginfo[0];
$srcHeight = $imginfo[1];
$ratioWidth = $srcWidth/$newWidth;
$ratioHeight = 0;
$destWidth = $newWidth;
$destHeight = $srcHeight / $ratioWidth;
// Choose method for thumb creation
switch($method)
{
case "im" :
{
// Resize the picture
exec("convert -quality 100 -antialias -sample \"".$destWidth."x".(int)$destHeight."\" \"$src_file\" \"$dest_file\"");
break;
}
case "php" :
{
$src_img = imagecreatefromjpeg($src_file);
$dst_img = imagecreate($destWidth,$destHeight);
imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $destWidth,(int)$destHeight, $srcWidth, $srcHeight);
imagejpeg($dst_img, $dest_file, 100); // Quality = 100
imagedestroy($src_img);
imagedestroy($dst_img);
break;
}
default:
{
// Resize the picture
exec("convert -quality 100 -antialias -sample \"".$destWidth."x".(int)$destHeight."\" \"$src_file\" \"$dest_file\"");
break;
}
} // End switch
return $dest_file;
}
function album_upload_picture($file, $filename)
{
global $config;
//include("config.inc.php");
$filepath = "$config[fullpath]"."userpics/"; // Change upload path in config.inc.php
$destinationname = $filepath.$filename;
if ($file != "none")
{
if(move_uploaded_file($file, $destinationname))
{
chmod($destinationname, 0644);
return $filename;
}
else
return false;
}
else
return false;
}
// Lists all albums in a dropdown-menu.
function getAlbumsUploadable()
{
global $config;
$connection = db_connect();
$result = mysql_query("SELECT * FROM $config[TABLE_ALBUMS] WHERE uploads='YES' ORDER BY description ASC");
$albums = array();
return db_result_to_array($result);
}
function show_picturemenu($id)
{
echo "<div class=\"admin_menu\">[ <a href=\"delete_picture.php?id=$id\" class=\"adm_menu\" onclick=\"return confirmPicture($id)\"\">DELETE</a> ]</div>";
}
function show_picturemenu_small($id)
{
echo "<div class=\"admin_menu_thumb\">[ <a href=\"delete_picture.php?id=$id\" class=\"adm_menu\" onclick=\"return confirmPicture($id)\"\">DELETE</a> ]</div>";
}
function show_commentsmenu($id)
{
echo "<div class=\"admin_menu_thumb\" align=\"center\">[ <a href=\"delete_comment.php?id=$id\" class=\"adm_menu\" onclick=\"return confirmComment($id)\"\">DELETE</a> ]</div>";
}
function show_albummenu($id)
{
echo "<div class=\"admin_menu\">[ <a href=\"delete_album.php?id=$id\" class=\"adm_menu\" onclick=\"return confirmAlbum($id)\"\">DELETE</a> ]</div>";
}
// Checks if the filetype is allowed.
function okfiletype($filename)
{
global $config;
for($i = 0; $i < count($config['filetypes']); $i++)
{
if(strtolower($config['filetypes'][$i]) == strtolower(substr($filename, -3)) || strtolower($config['filetypes'][$i]) == strtolower(substr($filename, -4)))
return true;
}
return false;
}
// Rename file if filename is the same
function rename_file($filename, $nr)
{
$pos = strrpos($filename, ".");
$name = substr($filename, 0, $pos);
$ext = substr($filename, $pos, strlen($filename)-$pos);
if(ereg("[0-9]", substr($name, -1) ))
$string = substr($name, 0, strlen($name)-1) . "$nr" . "$ext";
else
$string = "$name" . "_$nr" . "$ext";
return $string;
}
?>
Håber der er en der kan hjælpe mig
