Click to See Complete Forum and Search --> : Need help with Code.


StaceyB
01-30-2008, 10:55 AM
Hi! I am customizing this freeware that allows users to vote on photos. I have everything perfect except the photos are not displaying. If someone could take a quick look at my php file and let me know about this particular code line.

<?if($current_photo_id){?><img src=<?=get_thumb_url($current_photo_url,$site_blank_img_url)?> border=0>

Why isn't it returning any images. What settings should I check?

The complete page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Photovote</TITLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="style.css">
<SCRIPT type="text/javascript" language="JavaScript" src="lib.js"></SCRIPT>
</HEAD>
<BODY text=#000000 vLink=#000000 aLink=#000000 link=#006699 bgColor=#ffffff
leftMargin=0 topMargin=0 rightMargin=0 marginwidth="0" marginheight="0">

<CENTER>
<TABLE cellSpacing=0 cellPadding=5 width=760 border=0>
<TBODY>
<TR bgColor=#ffffff>
<TD vAlign=bottom align=left width=203>
<DIV align=left><A href="#">
<IMG src="picturevoting.gif" alt="Vote for pictures" border=0></A>
</DIV>
</TD>
<TD vAlign=bottom noWrap align=right width=537>&nbsp; </TD>
</TR>
</TBODY>
</TABLE>
</CENTER>
<FORM name=main action=index.php method=post>
<INPUT type=hidden name=imgid value="<?=$current_photo_id?>">
<INPUT type=hidden name=image value="<?=$current_photo_url?>">
<INPUT type=hidden name=c value="<?=$c?>">
<INPUT type=hidden name=vote value="0">
<TABLE cellSpacing=10 cellPadding=0 width=100% border=0>
<tr><td align=center>
<TABLE cellSpacing=0 cellPadding=0 width=100% border=0>
<TR bgColor=#990033>
<TD>
<P>
<span class=header>
<font color=#ffffff>
&nbsp;
Rate this picture between 10-best and 1-worst</font>
</span>
</P>
<TABLE cellSpacing=5 cellPadding=0 width="100%" align=center border=0>
<TR>
<TD vAlign=top bgColor=#f7f7f7>
<TABLE width=100% border=0>
<TR>
<TD vAlign=top align=right width=40>
<?if($current_photo_id and $current_user_id){?>

<TABLE cellSpacing=0 cellPadding=2 bgColor=#006699 background=bar.gif border=0>
<script language=javascript>
function writeVote(rate,text){document.write('<TR><TD vAlign=center noWrap align=right><FONT color=#ffffff >'+text+'<INPUT onclick="this.form.submit()" type=radio value='+rate+' name=vote></FONT></TD></TR>');}
writeVote(10,'Vote&nbsp;<br>10');
for(var i=9;i>0;i--){writeVote(i,i);}
</script>
</TABLE>

<?}else{?>

&nbsp;

<?}?>
</TD>
<TD background=grid.gif vAlign=top align=left>
<p>
<?if($current_photo_id){?><img src=<?=get_thumb_url($current_photo_url,$site_blank_img_url)?> border=0>
<BR>
<BR>

<?}else{?>

There is no picture in queue or all pictures are showed

<?}?>
</p>

<?/***20040809***/?>
<p align=left>
<b><?=$current_photo_desc?></b><br>
Number of votes: <b><?=$current_photo_votes?></b><br>
Average vote: <b><?=number_format($current_photo_rating,2)?></b><br>
<hr>
</p>

<p align=left>
<span class=small>
Photovote is designed to be a fun way to vote your opinion
for pictures submitted by admin of this website.
<?if($current_photo_id){?>

<br>
<A href="mailto:<?=$adm_email?>">Click here</A>
to report to us if the picture above is broken, copyrighted, or inappropriate.

<?}?>
</span>
</p>
<p align=right>
<span class=small>Copyright
<a style="{text-decoration:none;}" href="http://www.ecomstudio.net">Advanced eBusiness Studios</a> 2002 All Rights Reserved
&nbsp;
</span>
</p>
</TD>
</TR>
</TABLE>
</TD>
<TD vAlign=top width=150 noWrap>
<TABLE bgColor=#e0e0e0 width=100% cellPadding=5 border=0>
<TR>
<TD>
<?if($show_vote){?>

<br>
<img src=<?=$voted_thumb_url?> border=0>
<br>Your Vote:&nbsp;<?=$vote?>
<br>Overall Vote:&nbsp;<?=$vote_average?>
<br>Number of Votes:&nbsp;<?=$count_vote?>
<br>Position:&nbsp;<?="$position of $total"?>

<?}?>
<BR>
<BR>
<P><A href="show.php?c=all&w=t">Top&nbsp;<?=$item_maxshow?></A>
<BR><A href="show.php?c=all&w=b">Bottom&nbsp;<?=$item_maxshow?></A>
<BR><A href="show.php?c=all&w=n">Newest Pictures</A>
<p>
<?=$users_online?>&nbsp;users online
</p>
<p>
<SELECT onchange="window.location.reload('index.php?c='+this.value);" name=c>
<OPTION <?=make_selected($c,"")?> value="">-- Category --</OPTION>
<OPTION <?=make_selected($c,"all")?> value="all">(all)</OPTION>
<? show_select_option_category($c); ?>
</SELECT>
</p>
<BR>
&nbsp;
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</td></tr>
</table>
</FORM>

</BODY>
</HTML>


Greatly appreciated.

stmosaic
01-30-2008, 01:35 PM
img src=<?=get_thumb_url
Shouldn't that be img src=<?$get_thumb_url

scubasteve01048
01-30-2008, 01:48 PM
get_thumb_url($current_photo_url,$site_blank_img_url)
This appears to be a function call can you post the full code because it appears we are missing your function.:)

StaceyB
01-30-2008, 02:18 PM
Thanks.. btw the code was correct as it was img src=<?=get_thumb_url
Shouldn't that be img src=<?$get_thumb_url My images are getting posted to my SQL database backend and when I do a view source, I can see that the link to the images is correct, however, I am unable to open the images. I am getting the "403 Forbidden" error for my larger images. So, I believe that is my problem. The thumbnails which are in the same directory can be opened without any error and they are showing up on the page.

Any clues?

btw, here's the full code with the function at the bottom:

<?
/****************************************
SPV: Simple Photovoting. Free (GPL) Package
Release Date: March 10, 2003
Release Version: 1.3F
Designed and Developed by Advanced eBusiness Studios
Copyright (c) 2003 Advanced eBusiness Studios
Showcase: http://www.ecomstudio.net/sales
Contact email: sales@ecomstudio.net
*
This program is free software. You can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 2 of the License, or any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
****************************************/
//
//
require "function.db.inc.php";
//
//Featured
//
function password_ok($password){
//This function checks admin login password with [$adm_password]
//Can be re-defined for security. For example you can use MD5 encoding
global $adm_password;
return ($password==$adm_password);
}
function session_login(){
//Reserved for user login checking
return session_is_registered('user_login');
}
function session_admin(){
return session_is_registered('admin_login');
}
function show_all_option($c){
//Check if no category is selected
if(!$def_catgroup) return ($c=="all" or $c=="");
}
function show_select_option_category($selected_item=""){
global $def_categories, $def_categories_names;
for($i=0;$i<sizeof($def_categories);$i++){
$cat = $def_categories[$i];
$cat_name = $def_categories_names[$i];
$selected = make_selected($selected_item,$cat);
echo "<OPTION $selected value=$cat>$cat_name</OPTION>\n";
}
}
function show_cat($v){
global $def_categories, $def_categories_names, $def_catunknown;
for($i=0;$i<sizeof($def_categories);$i++){
if($v==$def_categories[$i]) return $def_categories_names[$i];
}
return $def_catunknown;
}
function show_admin_page_links($records,$offset,$category="",$key=""){
global $list_maxshow;
$pages = ceil($records/$list_maxshow);
if($pages>1){
for($i=1;$i<=$pages;$i++){
$pageoffset = ($i-1)*$list_maxshow;
$script = "getAdminPhp($pageoffset,'$category','$key')";
if($pageoffset!=$offset)
print("&nbsp;<a href=\"javascript:$script;\">$i</a>");
else
print("&nbsp;$i");
}
}
}
//
//Output
//
function show_yesno($v){
if($v) return "Yes";
else return "-";
}
function show_desc($v){
if($v) return $v;
else return "(Not specified)";
}
//
//Common
//
function make_checked($list,$val){ //Obsolete
$list = ",,".$list.",";
if(strlen($val)>0 && strpos($list,",".$val.",")>0) return "checked";
}
function make_selected($item,$val){ //Obsolete
return ($item==$val and strlen($item)==strlen($val))?"selected":"";
}
function in_list($list,$item){
//This [$list] is comma-separated string
return ereg(",$item,",",$list,");
}
function add_list($list,$item,$is_num=true){
//Add an item to a comma-separated list
if($is_num){
if($list and $item) return "$list,$item";
else if($item) return $item;
else return "";
}else{
return "$list,$item";
}
}
//
//Files processing
//
function get_filetype($fname){
return substr($fname,strrpos($fname,".")+1);
}
function resizer_main($tmp_name,$name,$w,$h,$folder,$prefix,$quality,$imagecreatetruecolor=true,$imagecopyres ampled=true){
if(trim($tmp_name)=="" or trim($tmp_name)=="none") return false;
$arr_img = image_from_upload($tmp_name);
if($arr_img["w"]!=$w and $arr_img["h"]!=$h){
$wh = get_sizes($arr_img["w"],$arr_img["h"],$w,$h);
$img_res = img_get_resized(
$arr_img["img"],
$arr_img["w"],
$arr_img["h"],
$wh["w"],
$wh["h"],
$imagecreatetruecolor,
$imagecopyresampled);
} else {
$img_res = $arr_img["img"];
}
ImageJPEG($img_res,"$folder/$prefix$name",$quality);
return "$prefix$name";
}
function image_from_upload($uploaded_file){
$img_sz = getimagesize($uploaded_file);
switch($img_sz[2]){
case 1:
$img = ImageCreateFromGif($uploaded_file);
break;
case 2:
$img = ImageCreateFromJpeg($uploaded_file);
break;
case 3:
$img = ImageCreateFromPng($uploaded_file);
break;
case 4:
$img = ImageCreateFromSwf($uploaded_file);
break;
default:
die("This type is not supported");
}
return array("img"=>$img,"w"=>$img_sz[0],"h"=>$img_sz[1],"type"=>$img_sz[2],"html"=>$img_sz[3]);
}
function get_sizes($src_w,$src_h,$dst_w,$dst_h ){
$mlt_w=$dst_w/$src_w;
$mlt_h=$dst_h/$src_h;
$mlt=($mlt_w<$mlt_h)?$mlt_w:$mlt_h;
if($dst_w=="*") $mlt=$mlt_h;
if($dst_h=="*") $mlt=$mlt_w;
if($dst_w=="*" && $dst_h=="*") $mlt=1;
$img_new_w=round($src_w*$mlt);
$img_new_h=round($src_h*$mlt);
return array("w"=>$img_new_w,"h"=>$img_new_h,"mlt_w"=>$mlt_w,"mlt_h"=>$mlt_h,"mlt"=>$mlt);
}
function img_get_resized($img_original,$img_w,$img_h,$img_new_w,$img_new_h,$imagecreatetruecolor=true,$imagec opyresampled=true){
$err_create = "Failed to create image";
$err_resize = "Failed to resize image";
if($imagecreatetruecolor && function_exists("imagecreatetruecolor")){
$img_resized = imagecreatetruecolor($img_new_w,$img_new_h) or die($err_create);
}else{
$img_resized = imagecreate($img_new_w,$img_new_h) or die($err_create);
}
if($imagecopyresampled && function_exists("imagecopyresampled")){
imagecopyresampled($img_resized,$img_original,0,0,0,0,$img_new_w,$img_new_h,$img_w,$img_h) or die($err_resize);
}else{
imagecopyresized($img_resized,$img_original,0,0,0,0,$img_new_w,$img_new_h,$img_w,$img_h) or die($err_resize);
}
return $img_resized;
}
function get_thumb_url($thumb,$blank){
if(!file_exists($thumb)) return $blank;
else return $thumb;
}
?>

Truly appreciative.

StaceyB
01-30-2008, 02:28 PM
Ok, I found another function of interest.

<? show_admin_page_links($this_total,$n,$c,$key); ?>
Full page code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Photovote Pictures Manager</TITLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="style.css">
<SCRIPT type="text/javascript" language="JavaScript" src="lib.js"></SCRIPT>
</HEAD>
<BODY text=#000000 vLink=#000000 aLink=#000000 link=#006699 bgColor=#ffffff
leftMargin=0 topMargin=0 rightMargin=0 marginwidth="0" marginheight="0">

<BR>
<TABLE borderColor=#000000 cellSpacing=0 cellPadding=2 width=740 align=center bgColor=#d7e2ee border=1>
<TBODY>
<TR>
<TD vAlign=top bgColor=#000066 colSpan=2>
<DIV align=center>
<B><FONT color=#ffffff>Photovote Admin Panel</FONT></B>
</DIV>
</TD>
</TR>
<TR vAlign=top align=middle>
<TD colSpan=2><BR>
<FORM name=browse action=admin.php method=post>
<input type=hidden name=action value="">
<input type=hidden name=abortlist value="">
<input type=hidden name=locked value="<?=$locked?>">
<TABLE borderColor=#000000 cellSpacing=0 cellPadding=5 width=720 bgColor=#e1e1e1 border=2>
<TBODY>
<TR vAlign=top bgColor=#000066>
<TD>
<DIV align=center>
<FONT color=#ffffff>
<B>Browse Pictures</B>
<br>
Click image description to edit its content
</FONT>
</DIV>
</TD>
</TR>
<TR vAlign=top>
<TD>
<DIV align=center>
<P>
<SELECT name=c onchange="document.browse.submit();">
<OPTION <?=make_selected($c,"")?> value="">-- Category --</OPTION>
<OPTION <?=make_selected($c,"all")?> value="all">(all)</OPTION>
<? show_select_option_category($c); ?>
</SELECT>
</P>
</DIV>
<TABLE cellSpacing=1 cellPadding=2 width=100% align=center border=0>
<TBODY>
<TR bgColor=#000066>
<TD width="8%">&nbsp;<a href="admin.php?c=<?=$c?>&key=id desc"><FONT color=#ffffff>ID</FONT></a></TD>
<TD width="40%">&nbsp;<a href="admin.php?c=<?=$c?>&key=description"><FONT color=#ffffff>Description</FONT></a></TD>
<TD width="20%">&nbsp;<a href="admin.php?c=<?=$c?>&key=category"><FONT color=#ffffff>Category</FONT></a></TD>
<TD width="10%">&nbsp;<a href="admin.php?c=<?=$c?>&key=rating desc"><FONT color=#ffffff>Rating</FONT></a></TD>
<TD width="8%">&nbsp;<a href="admin.php?c=<?=$c?>&key=count_vote desc"><FONT color=#ffffff>Votes</FONT></a></TD>
<TD width="7%">&nbsp;<a href="admin.php?c=<?=$c?>&key=suspended"><FONT color=#ffffff>Locked</FONT></a></TD>
<TD width="7%">&nbsp;<a href="javascript:document.browse.action.value='abort'; document.browse.abortlist.value=getlist(document.browse,'abort'); document.browse.submit();"><FONT color=#ffffff>Delete</FONT></a></TD>
</TR>
<?for($i=0;$i<$resultrows;$i++){?>

<TR bgColor=#ffffff>
<TD><A href="javascript:void(0);" onclick="fullScreen('<?=$resultset[$i][link]?>');"><?=$resultset[$i][id]?></A>&nbsp;</TD>
<TD><A href="javascript:void(0);" onclick="scrollScreen('edit.php?id=<?=$resultset[$i][id]?>');" style="{text-decoration:none}"><?=$resultset[$i][description]?></A>&nbsp;</TD>
<TD><?=$resultset[$i][category]?>&nbsp;</TD>
<TD><?=$resultset[$i][rating]?>&nbsp;</TD>
<TD><?=$resultset[$i][count_vote]?>&nbsp;</TD>
<TD><?=$resultset[$i][suspended]?>&nbsp;</TD>
<TD><input name=abort value=<?=$resultset[$i][id]?> type=checkbox>&nbsp;</TD>
</TR>

<?}?>
</TBODY>
</TABLE>
<CENTER>
<? show_admin_page_links($this_total,$n,$c,$key); ?>
</CENTER>
</TD>
</TR>
</TBODY>
</TABLE>
</FORM>
<P align=center>
<b>Add New Picture</b>
<br>
Maximum file size allowed: <?=number_format($max_file_size/1024,0)?>Kb
<br>
Thumbnail is auto-generated for JPEG only
<FORM name=upload action=admin.php method=post enctype=multipart/form-data>
<INPUT TYPE=hidden name=MAX_FILE_SIZE value=<?=$max_file_size?>>
<input style="{width:300px;}" name=photodesc value="(Picture Description)">
<br>
<SELECT style="{width:300px;}" name=photocat>
<? show_select_option_category(); ?>
</SELECT>
<br>
<input style="{width:300px;}" type=file name=photodata>
<br>
<input style="{width:300px;}" type=submit value="Upload Picture">
<br>
<br>
separate thumbnail
<br>
<input style="{width:300px;}" type=file name=thumbdata>
</form>
<A href="admin.php">Return To Admin Main Menu</A>
<br><A href="index.php">Return To Main Page</A>
<br>&nbsp;
</P>
</TD>
</TR>
</TBODY>
</TABLE>

</BODY>
</HTML>

Here's the function:
function show_admin_page_links($records,$offset,$category="",$key=""){
global $list_maxshow;
$pages = ceil($records/$list_maxshow);
if($pages>1){
for($i=1;$i<=$pages;$i++){
$pageoffset = ($i-1)*$list_maxshow;
$script = "getAdminPhp($pageoffset,'$category','$key')";
if($pageoffset!=$offset)
print("&nbsp;<a href=\"javascript:$script;\">$i</a>");
else
print("&nbsp;$i");

Here's an example of the links that are forbidden= (ie. 1.jpg; 2.jpg; 3.jpg)
Links not forbidden= (ie. s1.jpg; s2.jpg; s3.jpg)
All these files are in the same subdirectory! So it's not a permissions problem, right?

Hope this helps to explain problem.

jasonahoule
01-30-2008, 02:38 PM
Are you images in the same directory as the page serving them? If not then you need to put the correct path.

scubasteve01048
01-30-2008, 02:40 PM
403 error ussually means that the directory which includes the files you are trying to access is restricted by your web server. For example if you type in the url:

http://www.yoursite.com/images/

if your web server is configured to not list files in a directory it will throw the 403 error.

Now if you were to type in:

http://www.yoursite.com/images/logo.gif

This would return the file because it's a direct hit and your not querying the server to list all the file in the directory.

When you view your source code do you notice if it is using relative links to the images of absolute links? The difference is simple: relative links do not include the url.

Perhaps the path is wrong or your server is configured in-correctly. I would check the path to the images again.

StaceyBa
01-30-2008, 02:57 PM
Thank you for your response. I'll check the source code again. So it doesn't matter that I can access image files within the same directory? See my previous post.

scubasteve01048
01-30-2008, 03:17 PM
Can you post the link to an image that works and then post a link to an image that dosn't work where both images reside in the same directory.

StaceyBa
01-30-2008, 03:23 PM
The link is relative:<img src=images/1.jpg border=0>
Yes, I can:
http://www.mydomain.com/FreeGPL-13F/images/1.jpg - Gives Error
http://www.mydomain.com/FreeGPL-13F/images/s1.jpg- No Error, Shows Image

scubasteve01048
01-30-2008, 03:47 PM
The link is relative:<img src=images/1.jpg border=0> Yes, I can:
http://www.mydomain.com/FreeGPL-13F/images/1.jpg - Gives Error
http://www.mydomain.com/FreeGPL-13F/images/s1.jpg- No Error, Shows Image
Exactly how large are the files you are serving that give errors. does the file itself have the wrong permissions on the server? Do you host this site or does someone else host it? I would contact your host provider if you don't host it and have them look at:

the permissions on that file
If there is restrictions on how much data you can transfer per requestI am not to knowledgeable on server settings but if i was in your shoes thats what i would do!:D

StaceyBa
01-30-2008, 03:49 PM
Thanks for all your help.:) I guess it's a permissions problem after all.