Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Re: Image Avatars? Possible or just crazy talk?

Quote Reply
Re: Image Avatars? Possible or just crazy talk? In reply to
Hi!

I would love to, but to tell you the truth, don't remember much of it myself...If I'm not mistaken it is done pretty much the same way as the normal file upload mod. I've pasted some pieces of what I remember down here...maybe that can help. Sorry if it doesn't but it has been a little while ;(

** From Config file **

# File upload parameters
# --------------------------------------------------------
#
# File uploads -- if you want to be able to upload files, set this to 1
$db_upload = 1;

# Full path to directory for uploaded files -- NOT A URL!!!! No trailing slash please.
$SAVE_DIRECTORY = "/home/paxbrasi/paxbrasilis-www/br/images/members";

# Full URL to directory for uploaded files. No trailing slash please.
$SAVE_DIRECTORY_URL = "http://www.paxbrasilis.com/br/images/members";

# Defines the number of bytes that can be uploaded. Files that exceed
# this limit will not be saved on the server. Set this to zero in order to
# disable size checking.
$MAXIMUM_UPLOAD = 100000;

# List of allowable file extensions. If the file does not have one of the extensions
# listed, it will not be saved to the server. The format for the setting is
# \.[extension]$ If you want to allow more than one extension, separate the options by
# a | character.
$ALLOWED_EXT = '\.gif$|\.jpg$|\.jpeg$';


...
Graphic => [19,'alpha',0,255,0,'','Yes'],
Author => [20,'alpha',0,255,0,'',''],
...

** From DB.cgi **

sub validate_upload {
# --------------------------------------------------------
my ($filekey,$filename,$newfilename,$extlength,$filehandle,$totalbytes,$buffer,$bytes,@extensions,@ext);

$| = 1;

$filekey = $query->param("Filename");
$newfilename = $in{$db_key};

if (!(-e $SAVE_DIRECTORY)) {
return "The directory doesn't exist. Make sure that this directory is a complete path name,<BR>
not a URL or something similar. It should look similar to<BR>
/home/username/public_html/uploads";
}
if (!(-W $SAVE_DIRECTORY)) {
return "The directory isn't writable. Make sure that this directory is writable by all users.<BR>
At your UNIX command prompt, type chmod 777 $SAVE_DIRECTORY";
}
if (!(-d $SAVE_DIRECTORY)) {
return "The directory you specified isn't really a directory.<BR>
Make sure that this is indeed a directory and not a file.";
}

if ($filekey =~ /([^\/\\]+)$/) {
$filename = $1;
$extlength = length($filename) - index($filename,".");
$filename = $newfilename . lc(substr($filename,-$extlength,$extlength));
unless ($filename =~ /$ALLOWED_EXT/) {
$ALLOWED_EXT =~ s/\\//g;
$ALLOWED_EXT =~ s/\$//g;
@ext = split (/\Q|\E/o,$ALLOWED_EXT);
$ALLOWED_EXT = join(" or ",@ext);
return "Only files with the following extension(s) are allowed: $ALLOWED_EXT";
}
}
else {
return "You attempted to upload <B>$filekey</B> that isn't properly formatted. Please rename the file
on your computer, and attempt to upload it again. Files may not have forward or backward slashes in
their names. Also, they may not be prefixed with one (or more) periods.";
}

opendir (GRAPHIC, "$SAVE_DIRECTORY") or &cgierr("unable to open directory in delete records: $SAVE_DIRECTORY. Reason: $!");
@files = readdir(GRAPHIC);
closedir (GRAPHIC);
$file_test = $in{$db_key} . ".";
foreach $file (@files) {
if ($file =~ /^$file_test/) {
unlink ("$SAVE_DIRECTORY/$file");
}
}
if (!open(OUTFILE, ">$SAVE_DIRECTORY\/$filename")) {
return "There was an error opening '$SAVE_DIRECTORY\/$filename' for Writing.\n";
}

binmode(OUTFILE); # This is needed to work on Windows/NT platforms.

while ($bytes = read($filekey,$buffer,1024)) {
$totalbytes += $bytes;
print OUTFILE $buffer;
}

close($filekey);
close(OUTFILE);

chmod (0666, "$SAVE_DIRECTORY\/$filename");

if ($totalbytes > $MAXIMUM_UPLOAD && $MAXIMUM_UPLOAD > 0) {
unlink "$SAVE_DIRECTORY\/$filename";
return "Filename<BR>
You have reached your upload limit.<BR>
Your file contains <B>$BytesRead $totalbytes</B> bytes.<BR>
This exceeds the maximum limit of <B>$MAXIMUM_UPLOAD</B> bytes.<BR>
Your file was not saved.<BR>
Please try again.";
}

return "ok";
}


Hope it helps :)

Subject Author Views Date
Thread Image Avatars? Possible or just crazy talk? lubatico 2791 Nov 17, 2000, 9:08 AM
Thread Re: Image Avatars? Possible or just crazy talk?
Rob 2701 Nov 17, 2000, 2:40 PM
Post Re: Image Avatars? Possible or just crazy talk?
lubatico 2670 Nov 18, 2000, 12:52 AM
Thread Re: Image Avatars? Possible or just crazy talk?
TheFox 2660 Dec 28, 2000, 10:41 PM
Thread Re: Image Avatars? Possible or just crazy talk?
lubatico 2644 Dec 29, 2000, 8:14 AM
Post Re: Image Avatars? Possible or just crazy talk?
TheFox 2655 Dec 29, 2000, 10:09 AM