Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Image Avatars? Possible or just crazy talk?

Quote Reply
Image Avatars? Possible or just crazy talk?
Greetins, everyone!

I've got my DBMan SQL working to perfection (finally!) and thanks to all of you! :)

Just have one question: I have my database set up so people can upload their image to their records. Is there any way to have them choose between an uploaded image or an already saved image (say, a headshot of batman) instead? Do I just change the form or providing those graphics or should I also mess with the code?

Thanks in advance :)

Quote Reply
Re: Image Avatars? Possible or just crazy talk? In reply to
Hi lubatico...just a quick question...are using JPDeni's upload mods version 1 or 2 ....I'm currently trying to modify version 1 to dbsql.....but I'm encountering some problems there....thanks Rob

Quote Reply
Re: Image Avatars? Possible or just crazy talk? In reply to
Hi, Rob. I don't really konw which one I'm using....I'm using the one that was pointed out in the previous disucssion (about 2 weeks or 3 ago). I think it is number 1, with some small sql modifications. Sounds confusing? Yep. It sure is. Sorry. It's 4 am already :)

Best wishes

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

Can you show how you made the file upload mod work with DBMANSQL??

Thanks



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 :)

Quote Reply
Re: Image Avatars? Possible or just crazy talk? In reply to
Is it work with DbmanSQL??

regards