Posted by dabbler (leah), 21 January 2004
Hi, I'm trying to install a mod that works for a lot of other people, but does not want to work for me (and a couple of others as well), so I think it must be server related. It's an avatar upload add-on for a Profile.
What it does do is create a file with the correct filename in the upload directory, however, the file is 0kb. Since it is creating a file, does this confirm that chmod is not an issue? I would think so, but I'm not sure. I've looked at a lot of other pages and tried a lot of variations with no luck.
Posting the bulk of the code in hopes someone has some ideas on what might work.
Code:sub UploadAvatar { if(!$allowuplava) { &fatal_error($uplavatxt{'8'}); }
if ($INFO{'username'} =~ m~/~){ &fatal_error($txt{'224'}); } if ($INFO{'username'} =~ m~\\~){ &fatal_error($txt{'225'}); } if($username ne $INFO{'username'} && $settings[7] ne 'Administrator') { &fatal_error($txt{'80'}); } if(!-e ("$memberdir/$INFO{'username'}.dat")){ &fatal_error("$txt{'453'} -- $INFO{'username'}"); } if($allowpics) { opendir(DIR, "$facesdir") || fatal_error("$txt{'230'} ($facesdir)! $txt{'681'}"); closedir(DIR); }
$yymain .= qq~ <form action="$cgi;action=uploadavatar2;username=$INFO{'username'}" method="POST" enctype="multipart/form-data" name="avatarupload"> <table border=0 width=720 cellspacing=1 bgcolor="$color{'bordercolor'}" class="bordercolor" align="center"> <tr> <td class="titlebg" bgcolor="$color{'titlebg'}" height="30"> <img src="$imagesdir/profile.gif" alt="" border="0"> <font size=2 class="text1" color="$color{'titletext'}"><b>$uplavatxt{'1'}</b></font></td> </tr><tr> <td class="windowbg" bgcolor="$color{'windowbg'}"> <table border=0 width="100%" cellpadding="3"> <tr> <td><font size="2"><B>$uplavatxt{'1'}:</B></font><br><font size="1">$uplavatxt{'2'} <b>$uplavasize kB</b>.</font></td> <td valign="top"><input type="file" name="umafile" size="37"></td> </tr> </table><BR> </td> </tr><tr> <td class="catbg" bgcolor="$color{'catbg'}" height="25" align="center"><font size=2><BR> <input type=submit name=moda value="$uplavatxt{'1'}"><BR><BR> </font></td> </tr> </table> </form> ~; $yytitle = $uplavatxt{'1'}; &template; exit; }
sub UploadAvatar2 { if(!$allowuplava) { &fatal_error($uplavatxt{'8'}); }
# make sure this person has access to this profile if($username ne $INFO{'username'} && $settings[7] ne 'Administrator') { &fatal_error($uplavatxt{'7'}); }
use CGI; my $query = new CGI;
if ($query->param('umafile')) { $avatar = $query->param('umafile'); }
my $avat=lc($avatar);
if($avat =~ /\.jpg$/ || $avat =~ /\.gif$/ || $avat =~ /\.png$/) { my $type; $type=substr($avat,length($avat)-4,4); $avafile = "$INFO{'username'}$type"; } else { &fatal_error("$uplavatxt{'2'} $uplavasize kB"); }
$write_file = "$umauploaddir/$avafile";
fopen(AVADAT,">$write_file"); binmode $avatar; binmode AVADAT;
while (read($avatar,my $buffer,1024)) { print AVADAT $buffer; } fclose(AVADAT);
my @Inf=stat("$write_file");
if($uplavasize && $Inf[7]>$uplavasize*1024) { unlink("$write_file"); fatal_error("$uplavatxt{'9'} <b>$uplavasize kB</b>."); }
fopen(FILE, "$memberdir/$INFO{'username'}.dat"); @meminfos=<FILE>; fclose(FILE);
$meminfos[13] = "$umauploadurl/$avafile\n"; fopen(FILE, ">$memberdir/$INFO{'username'}.dat"); print FILE @meminfos; close(FILE);
&DelTemp;
$yySetLocation = qq~$boardurl/YaBB.$yyext?board=;action=profile;username=$INFO{'username'}~; &redirectexit; } |
|
Posted by admin (Graham Ellis), 21 January 2004
Yep, seen this before ... just trying to remember what the solution was

I think it IS server related, and to do with the end of line characters on the server - which are \r\n for Windows (carriage return, line feed) and \n (line feed) for almost everything else (Solaris, Unix, Linux OSX).
I also notice that your code uses an intermediate temporart file as a staging post for the data, but it doesn't check whether the file opens correctly for read / write. The symptom you describe could also be caused by the staging directory not being writable to the web server, even though the final destination is.
Posted by dabbler (leah), 23 January 2004
Thank you Graham, I'll try working at those suggestions.
This page is a thread posted to the opentalk forum
at
www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow
this link.