...

View Full Version : FileUpload -- "File of type" PROBLEM



que90nek
01-16-2003, 04:09 PM
From what I have seen this ought to be an easy question for all you guru's. Your help is appreciated in advance.

I have a pl/sql package that has in it some javascript. The javascript in question does an
upload of a file. It does this successfully. It pops up a window that allows the user to select the file that he/she wants.

Problem: Each of my browsers give DIFFERENT options

my Netscape 4.7 is the worst: In the place where it says "Files of type" it defaults to HTML
then gives 100 other choices including about 9 "javabeans" choices.

Netscape 7: gives one choice ALL IE 6: gives 3 choices gif, all, html

I want to be able to limit the choice to ONE....PDF. or at least have it default to that.

HELP.

Here is the code that I tried to do to fix the problem....

htp.p('<td><input type="file" name="upfile" alt="custom"pattern="\.(pdf)$"emsg="You can upload only PDF extention files"></td>');

ConfusedOfLife
01-16-2003, 05:58 PM
Hi, first of all javascript doesn't upload files, or at least I think so!
Also those pattern and emsg were new to me, I have to check them more thoroughly ( later ).

I wrote a piece of js that's very ugly indeed, but I think it works:


<body>
<form onsubmit="if ( !(/\.pdf/.exec(upload.value)) ) { alert('Just upload pdf files!'); return false; } ">
<input name="upload" type="File" accept="application/pdf" maxlength="">
<input type="Submit" value="Submit">

</form>


Happy Coding

mordred
01-16-2003, 05:59 PM
Please read the sticky thread, especially rule 2:
http://www.codingforums.com/showthread.php?s=&threadid=2090

Without seeing any source code in this matter no one can help beside random guessing. Also, don't paste server-side code in here, we don't know the content of variables or results of function calls.

que90nek
01-16-2003, 07:45 PM
My fault.

I read the rules, but because I am a novice I didnt know that this was SERVER side code.

I saw a similiar question in this area...in fact that is where i got some of the code.

So i posted mine.

Thanks for your help.

Seems as though ConfusedOfLife seemed to randomly guess the EXACT and CORRECT solution. Thanks again.

cg9com
01-16-2003, 08:29 PM
/me thinks your main problem was the accept="" attrib. you were missing.

que90nek
01-16-2003, 08:37 PM
....ok. The code DOES still work...

but the FILE OF TYPE options have not changed.

My manager is PICKY....she doesnt want all the choices even though i have the alert that checks for PDF anyway.

I am about to tell her it can't be done.



Am I looking in the wrong place?

cg9com
01-16-2003, 08:48 PM
are there alot of NS4 users that view the site?
you should tell your manager that coding for that browser is a waste of time.
i dont have a copy of it so i wouldnt be able to speculate on an exact way to fix the problem.
also i dont know if you dont want to post code or not, but that really would help.

que90nek
01-16-2003, 09:00 PM
Here's some of it....this part is not the part I need help with but it does what you all did in three lines.......

htp.p('<html>');
htp.p('<head>');
htp.p('<LINK REL="StyleSheet" HREF="/styles/main.css">');
htp.p('<title>Actions</title>');
htp.p('<script language="javascript1.3">');--changed javascript1.3 version
htp.p('function setExtension() {');
htp.p(' var cmat1 = "'||med_rec.cmat_id||'";');
htp.p(' var cmat2 = document.Form1.upfile.value.substring(document.Form1.upfile.value.lastIndexOf("\\") + 1,document.Form1.upfile.value.length);');
htp.p(' cmat2= cmat2.replace(/\.pdf/,"");');
htp.p(' document.Form1.EXT.value = document.Form1.upfile.value.substring(document.Form1.upfile.value.lastIndexOf(".") + 1,document.Form1.upfile.value.length);');
htp.p(' if (document.Form1.EXT.value != "pdf") {');
htp.p(' window.alert("Only pdf files may be uploaded to this system. Please select a file with a .pdf extention")');
htp.p(' document.Form1.upfile.select();');
htp.p(' document.Form1.upfile.focus();');
htp.p(' } else if (cmat1 != cmat2) {');
htp.p(' window.alert("The CMAT numbers must match. \nPlease rename the pdf '||med_rec.cmat_id||'.pdf");');
htp.p(' document.Form1.upfile.select();');
htp.p(' document.Form1.upfile.focus();');
htp.p(' } else {');
htp.p(' document.Form1.submit();');
htp.p(' }');
htp.p('}');
htp.p('</script>');


this is the part that counts...

htp.p('<FORM NAME="Form1" ENCTYPE="multipart/form-data" METHOD="POST" ACTION="/cgi-bin/fup_cgi.pl">');
htp.p('<INPUT TYPE="HIDDEN" NAME="YEAR" VALUE="'|| med_rec.year_created ||'">');
htp.p('<INPUT TYPE="HIDDEN" NAME="MONTH" VALUE="'|| med_rec.MONTH_created ||'">');
htp.p('<INPUT TYPE="HIDDEN" NAME="CMAT" VALUE="'|| med_rec.cmat_id ||'">');
htp.p('<INPUT TYPE="HIDDEN" NAME="MEDIUM_ID" VALUE="'|| p_medium_id ||'">');
htp.p('<INPUT TYPE="HIDDEN" NAME="ACTION_ID" VALUE="'|| p_action_id ||'">');
htp.p('<INPUT TYPE="HIDDEN" NAME="EXT">');
htp.p('<table border="2" cellspacing="0" cellpadding="0">');
htp.p(' <tr>');
htp.p(' <td>');
htp.p(' <table width="500" border="0">');
htp.p(' <tr>');
htp.p(' <td id="tableHeaderLeft" colspan="2">File Upload</td>');
htp.p(' </tr>');
htp.p(' <tr>');
htp.p(' <td id="tabledataright">Total Scanned Pages:</TD>');
htp.p(' <td><input type="text" size="20" name="p_total_scanned" value="'||med_rec.total_scanned||'"></TD>');
htp.p(' </tr>');
htp.p(' <tr>');
htp.p(' <td id="tabledataright">File:</td>');
--added code here to restrict to PDF....but it doesnt work!!!!!!!!!!!!
-- htp.p(' <td><input type="file" name="upfile" alt="custom" pattern="\.pdf"></td>');
htp.p(' <td><input type="file" name="upfile" accept="application/pdf" maxlength=""></td>');
--emsg="You can upload only PDF extention files"
htp.p(' </tr>');
htp.p(' </table>');
htp.p(' </td>');
htp.p(' </tr>');
htp.p('</table>');
htp.p('<table width="500" border="0">');
htp.p(' <tr>');
htp.p(' <td><a href="javascript1.3:setExtension();"><img src="/images/upload.gif" border="0" alt="Upload scanned Item"></A></td>');
htp.p(' <td id="tabledataright">');
htp.p(' <a href="medium.home"><img src="/images/med_mgr.gif" border="0" alt="Medium Manager"></a>');
IF UPPER(v_is_group) = 'G' THEN
htp.p(' <a href="view_actions.group_actions"><img src="/images/action_queue.gif" border="0" alt="Actions Queue"></a>');
ELSE
htp.p(' <a href="view_actions.indv_actions"><img src="/images/action_queue.gif" border="0" alt="Actions Queue"></a>');
END IF;
htp.p(' </td>');
htp.p(' </tr>');
htp.p('</table>');
htp.p('</form>');


if this is a server side question i can move it over there....

mordred
01-17-2003, 08:52 AM
Again, don't post server-side code you don't have a problem with. This apparently produces some HTML output and you view it with a browser, right? Then just select "view source" from your context menu and post the *output* of this server-side-script, not the script itself, thanks.

que90nek
01-17-2003, 02:46 PM
<html>
<head>
<LINK REL="StyleSheet" HREF="/styles/main.css">
<title>Actions</title>
<script language="javascript1.3">

function setExtension() {
var cmat1 = "2003013-0000094";
var cmat2 = document.Form1.upfile.value.substring(document.Form1.upfile.value.lastIndexOf("\\") + 1,document.Form1.upfile.value.length);
cmat2= cmat2.replace(/\.pdf/,"");
document.Form1.EXT.value = document.Form1.upfile.value.substring(document.Form1.upfile.value.lastIndexOf(".") + 1,document.Form1.upfile.value.length);
if (document.Form1.EXT.value != "pdf") {
window.alert("Only pdf files may be uploaded to this system. Please select a file with a .pdf extention")
document.Form1.upfile.select();
document.Form1.upfile.focus();
} else if (cmat1 != cmat2) {
window.alert("The CMAT numbers must match. \nPlease rename the pdf 2003013-0000094.pdf");
document.Form1.upfile.select();
document.Form1.upfile.focus();
} else {
document.Form1.submit();
}
}

</script>
</head>
<body>
<TABLE bgcolor=#CCCCFF cellpadding=4 cellspacing=0 border=0 width="100%">
<TR bgcolor=#CCCCFF>
<TD WIDTH = "96%" COLSPAN="2"><FONT COLOR="black" size="4" face="Verdana"><b>
Unstructured Data Form
<b></TD>
<TD><A HREF="../dhss/dhs.home" target="_top"><IMG SRC="/images/homeb.gif" ALIGN="right" V_ALIGN="top" BORDER="0" ALT="Home"></A></TD>
<TD><a href="#" onClick="alert('If you have questions concerning this Intranet please either:\rEmail the ORACLE SOFTWARE DEVELOPMENT GROUP in Lotus Notes or\rcall us at (703) 681-3279 ext. 152, 120, 108, or 119.')"> <IMG SRC="/images/helpb.gif" ALIGN="left" V_ALIGN="top" border="0" alt="Help"></a></td></tr>
<TR bgcolor = "navy" ROWSPAN = "1" COLSPAN = "4">
<TD ALIGN="left" height=15 COLSPAN = "4"><font color="white" size="2" face="Verdana"><b>
Document Management
</b></font></TD>
</TR>
</TABLE>
<SCRIPT language="JAVASCRIPT">


function PopMedium () {
var str = "width=600,height=400,resizable=yes,alwaysRaised,scrollbars=yes";
newWindow = window.open("medium.ro_ITEM?p_medium_id=62707", "MedWin", str);
}


</SCRIPT>
<TABLE width=100% BORDER = 0 CELLPADDING=3 CELLSPACING=3>
<TR>
<TD ALIGN="LEFT" VALIGN="BOTTOM" id="tableData" WIDTH="50%"><B>CMAT ID:</B>
&nbsp;
<A HREF="javascript:PopMedium();">2003013-0000094</A>
</TD>
<TD ALIGN="LEFT" VALIGN="BOTTOM" id="tableData"><B>Document Name:</B>
&nbsp;
QUE'S DOCUMENT
</TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="BOTTOM" id="tableData" WIDTH="50%"><B>Originator:</B>
&nbsp;

</TD>
<TD ALIGN="LEFT" VALIGN="BOTTOM" id="tableData"><B>Source:</B>
&nbsp;
US AIR FORCE
</TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="BOTTOM" id="tableData"><B>Associated Person:</B>
&nbsp;

</TD>
<TD ALIGN="LEFT" VALIGN="BOTTOM" id="tableData"><B>Relationship:</B>
&nbsp;
PREACHER
</TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="BOTTOM" id="tableData"><B>Total Pages:</B>
&nbsp;
2
</TD>
<TD ALIGN="LEFT" VALIGN="BOTTOM" id="tableData"><B>Classification:</B>
&nbsp;
RESTRICTED
</TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="BOTTOM" id="tableData"><B>Date Created:</B>
&nbsp;
01/13/2003
</TD>
<TD ALIGN="LEFT" VALIGN="BOTTOM" id="tableData"><B>Created By:</B>
&nbsp;
CMYLES
</TD>
</TR>
</TABLE>
<BR><BR>
<FORM NAME="Form1" ENCTYPE="multipart/form-data" METHOD="POST" ACTION="/cgi-bin/fup_cgi.pl">
<INPUT TYPE="HIDDEN" NAME="YEAR" VALUE="2003">
<INPUT TYPE="HIDDEN" NAME="MONTH" VALUE="JAN">
<INPUT TYPE="HIDDEN" NAME="CMAT" VALUE="2003013-0000094">
<INPUT TYPE="HIDDEN" NAME="MEDIUM_ID" VALUE="62707">
<INPUT TYPE="HIDDEN" NAME="ACTION_ID" VALUE="2891">
<INPUT TYPE="HIDDEN" NAME="EXT">
<table border="2" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="500" border="0">
<tr>
<td id="tableHeaderLeft" colspan="2">File Upload</td>
</tr>
<tr>
<td id="tabledataright">Total Scanned Pages:</TD>
<td><input type="text" size="20" name="p_total_scanned" value=""></TD>
</tr>
<tr>
<td id="tabledataright">File:</td>
<td><input type="file" name="upfile" accept="application/pdf" maxlength=""></td>
</tr>
</table>
</td>
</tr>
</table>
<table width="500" border="0">
<tr>
<td><a href="javascript1.3:setExtension();"><img src="/images/upload.gif" border="0" alt="Upload scanned Item"></A></td>
<td id="tabledataright">
<a href="medium.home"><img src="/images/med_mgr.gif" border="0" alt="Medium Manager"></a>
<a href="view_actions.indv_actions"><img src="/images/action_queue.gif" border="0" alt="Actions Queue"></a>
</td>
</tr>
</table>
</form>
</BODY>
</HTML>

mordred
01-17-2003, 04:36 PM
After going through your code and re-reading your original question, I come to the conclusion that your question is not related to JavaScript at all. You speak about the File Upload dialogue that permits you to select a file from your hard drive and the select list that lets you choose among groups of files to be seen in the dialogue.

What you ask for is just not doable. This File Upload dialogue is a feature of your browser that interacts with your OS, and unrelated to JavaScript. You can't such features with JavaScript. Eventually, you might invoke a more customizable dialogue in IE, working on an ActiveXObject if the security settings permit it. But that's not applicable for Netscape4 or Mozilla.

que90nek
01-17-2003, 05:14 PM
:thumbsup:

AND THAT, my friend...is what I wanted to hear!

Thank you.

I will tell my manager to only use netscape 6PLUS...and IE 6.


Thanks for your help. I have learned a lot.

cg9com
01-17-2003, 07:32 PM
hehe



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum