Gossamer Forum
Home : Products : DBMan : Customization :

Multiple UPload Mod - Adding Caption and Storing File Name

Quote Reply
Multiple UPload Mod - Adding Caption and Storing File Name
Hi All,

I have successfully installed file multiple file upload mod. I am now looking to make some changes and am a little stuck.

Each Record can have up to 5 attached photos I have now added a caption to each picture but i would now like to either rename each file from 1 to 5 or be able to store the url of the file within the database (i,e file1, file2 file3 etc and file1 - http://mywebsite/images/file1.jpg)so that the picture can be viewed on a seperate page with its caption.

Any Ideas much appreciated apolgies for being a little vague.
Quote Reply
Re: [jamesamorris] Multiple UPload Mod - Adding Caption and Storing File Name In reply to
I don't have a specific thread reference, but I'm sure the answer to this is within the FAQ noted below within the section "Images".

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Multiple UPload Mod - Adding Caption and Storing File Name In reply to
Thanx I have looked through the FAQ's and have managed to add a caption for each piccie but as yet cant find out how to write the URL to a field.
Quote Reply
Re: [LoisC] Multiple UPload Mod - Adding Caption and Storing File Name In reply to
Heres the code im using to write the url to a field but it doesnt seem to work?



if ($form_upload_add) {
print qq|<tr><td colspan=2><center><$font_color>You may attach up to $MAXIMUM_FILES photos to this diary entry.</font></center></td></tr>|;
for ($u=1;$u<=$MAXIMUM_FILES ;++$u) {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="115"><$font_color>Add Photo:</font></td>
<TD VALIGN="TOP" WIDTH="520">&nbsp;<INPUT TYPE="FILE" NAME="file-to-upload-$u" SIZE="50"></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="115"><$font_color>Photo Caption:</font></td>
<TD VALIGN="TOP" WIDTH="520">&nbsp;<INPUT TYPE="TEXT" NAME="CAPT$u" SIZE="50"></TD></TR>
<input type="hidden" name="PIC$u" value="file-to-upload-$u">|;

The hidden input is to try and write the url to the PIC$u(1 to 5) field.
Quote Reply
Re: [jamesamorris] Multiple UPload Mod - Adding Caption and Storing File Name In reply to
Hello,

I don't know if this will help. Here are the codes to show a record with one or multiple attachments. The attachments do not have to be a jpg file. In these codes, the extensions could be jpg, gif, pdf, doc or txt files. The codes were taken from JP Deni's threads.

----

In sub html_record_long

if (-e "$SAVE_DIRECTORY/$rec{$db_key}") {
opendir (GRAPHIC, "$SAVE_DIRECTORY/$rec{$db_key}") or &cgierr("unable to open directory: $SAVE_DIRECTORY/$rec{$db_key}. Reason: $!");
@files = readdir(GRAPHIC);
closedir (GRAPHIC);
foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
$extlength = length($file) - index($file,".");
$ext = substr($file,-$extlength,$extlength);
if ($ext =~ /^.doc/) {
print qq|<tr bgcolor="#f5f5f5"><td colspan=2 align=center><a class="five" href= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$file"><IMG SRC="$SAVE_DIRECTORY_URL/doc.gif" WIDTH="20" HEIGHT="20" ALIGN="BOTTOM" BORDER="0" NATURALSIZEFLAG="3"><br>download</a></td></tr>|;
} else {
if ($ext =~ /^.DOC/) {
print qq|<tr bgcolor="#f5f5f5"><td colspan=2 align=center><a class="five" href= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$file"><IMG SRC="$SAVE_DIRECTORY_URL/doc.gif" WIDTH="20" HEIGHT="20" ALIGN="BOTTOM" BORDER="0" NATURALSIZEFLAG="3"><br>download</a></td></tr>|;
} else {
if ($ext =~ /^.txt/) {
print qq|<tr bgcolor="#f5f5f5"><td colspan=2 align=center><a class="five" href= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$file"><IMG SRC="$SAVE_DIRECTORY_URL/txt.gif" WIDTH="20" HEIGHT="20" ALIGN="BOTTOM" BORDER="0" NATURALSIZEFLAG="3"><br>download</a></td></tr>|;
} else {
if ($ext =~ /^.TXT/) {
print qq|<tr bgcolor="#f5f5f5"><td colspan=2 align=center><a class="five" href= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$file"><IMG SRC="$SAVE_DIRECTORY_URL/txt.gif" WIDTH="20" HEIGHT="20" ALIGN="BOTTOM" BORDER="0" NATURALSIZEFLAG="3"><br>download</a></td></tr>|;
} else {
if ($ext =~ /^.pdf/) {
print qq|<tr bgcolor="#f5f5f5"><td colspan=2 align=center><a class="five" href= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$file"><IMG SRC="$SAVE_DIRECTORY_URL/pdf.gif" WIDTH="20" HEIGHT="20" ALIGN="BOTTOM" BORDER="0" NATURALSIZEFLAG="3"><br>download</a></td></tr>|;
} else {
if ($ext =~ /^.PDF/) {
print qq|<tr bgcolor="#f5f5f5"><td colspan=2 align=center><a class="five" href= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$file"><IMG SRC="$SAVE_DIRECTORY_URL/pdf.gif" WIDTH="20" HEIGHT="20" ALIGN="BOTTOM" BORDER="0" NATURALSIZEFLAG="3"><br>download</a></td></tr>|;
} else {
print qq|<tr bgcolor="#f5f5f5"><td colspan=2 align=center><img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$file"></td></tr>|;
}
}
}
}
}
}
}
}

-------

As you can see, you do not need to rename your files or store them. From View Record, I'm sure you could set up Javascript codes to view each attachment on a separate window.

Well, that's it.

Mikan
Quote Reply
Re: [mikan] Multiple UPload Mod - Adding Caption and Storing File Name In reply to
for some reason the only way i could get the filename to be sabed onto the db was by using

<tr>
<td width="400" colspan=2>Add Photo$u:

<input type="FILE" name="file-to-upload-$u" size="50">
<br><input type="hidden" name="IMAGE$u" value="file-to-upload-$u">
Photo Caption:

<input type="TEXT" name="CAPTION$u" size="50">
</td>
</tr>

but the problem is, that it saves the filename in the db as |file-to-upload-1|file-to-upload-2|
and so on

so the file name has to be saved somehow in the database

any ideas anyone?
Quote Reply
Re: [TKEP1008] Multiple UPload Mod - Adding Caption and Storing File Name In reply to
ok, with some java script i figured out how to svae the correct file, but it is saving the full relative path, so when i look at the db, where the filename should be it saved the whole path c:\blahblaj\thisdirectory\pic.jpg

is there a way i can either strip this down so that the hidden file or IMAGE$u in this case, would be stripped down tojust save the pic.jpg in that entry?

<tr>
<td width="400" colspan=2>Add Photo$u:
<input type="file" name="file-to-upload-$u" size="50" onChange="this.form.IMAGE$u.value=this.value;">

<br><input type="hidden" name="IMAGE$u" value="">
Photo Caption:

<input type="TEXT" name="CAPTION$u" size="50">
</td>
</tr>