Results 1 to 12 of 12

Thread: Please Help

  1. #1
    Join Date
    Jan 2004
    Location
    NY
    Posts
    5

    Unhappy Unanswered: Please Help

    Im New To ASP And Am Terible At It. I Made This From Random Bits Of Free Code I Found. The Problem: When i remove The Section With The *******'s, Everything Works Fine And Uploads The Pictures. Im Trying To Write To A Text file What Are In The TextFields(Text Boxes). I Keep Getting This Error:

    Error Type:
    Request object, ASP 0207 (0x80004005)
    Cannot use Request.Form collection after calling BinaryRead.
    /upload/uploadpic.asp, line 39

    Any Help Is Appreciated
    Thanks In Advance
    -Brian

    <%
    Const imageExts = ".gif,.jpg,.png,.jpeg,.bmp,.ico"
    Const MaxFileSize = &H180000
    Server.ScriptTimeout = 2000

    Dim DestinationPath
    DestinationPath = ("C:\Stored Files\uploadedfiles\")

    Dim Form: Set Form = New ASPForm %><!--#INCLUDE FILE="_upload.asp"--><%

    Server.ScriptTimeout = 1000
    Form.SizeLimit = &HA00000

    if len(Request.QueryString("UploadID"))>0 Then
    Form.UploadID = Request.QueryString("UploadID")'{/b}
    end if
    Const fsCompletted = 0

    If Form.State = fsCompletted Then

    if Form.State = 0 then
    response.write "<br><b>Upload result: Form was accepted.</b>"
    response.write "<br>Number of file fields:" & Form.Files.Count
    response.write "<br>Request total bytes:" & Request.TotalBytes
    Dim Field
    For each Field in Form.Files.Items
    response.write "<br>File:" & Field.FileName & ", size :" & (Field.Length \ 1024 +1) & "kB"

    if instr(1, imageExts & ",", Field.FileExt & ",", 1)>0 Then
    if Field.Length<=MaxFileSize Then

    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
    LogFile = ("C:\Stored Files\uploadedfiles\Log.txt.txt")
    Set OutputStream = FileObject.OpenTextFile (LogFile, ForAppending, True)
    OutputStream.WriteLine "Date: " + CStr(Now())
    OutputStream.WriteLine "IP: " + Request.ServerVariables ("LOCAL_ADDR")

    **********OutputStream.WriteLine "Year: " + request.form("CarYear")
    **********OutputStream.WriteLine "Model: " + request.form("CarModel")
    **********OutputStream.WriteLine "Your Email Address: " + request.form("Email")

    OutputStream.WriteLine " "
    OutputStream.Close
    Set OutputStream = Nothing
    Set FileObject = Nothing

    Field.Save DestinationPath
    response.write"<Font Color=green> <b>was stored to a disk.</b></font>"
    else
    response.write "<Font Color=red> <b>exceeds file limit</b> (" & (MaxFileSize \ 1024 +1) & "kB).</font>"
    end if
    else
    response.write "<Font Color=red><b> is not an image type </b> (" & imageExts & ").</font>"
    end if

    Next

    End If
    ElseIf Form.State > 10 then
    Const fsSizeLimit = &HD
    Select case Form.State
    case fsSizeLimit: response.write "<br><Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font><br>"
    case else response.write "<br><Font Color=red>Some form error.</Font><br>"
    end Select
    End If'Form.State = 0 then

    Dim UploadID, PostURL
    UploadID = Form.NewUploadID

    PostURL = Request.ServerVariables("SCRIPT_NAME") & "?UploadID=" & UploadID'{/b}

    %>


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <TITLE>ASP huge file upload - file size limit with progress bar.</TITLE>
    <STYLE TYPE="text/css">
    <!--TD {font-family:Arial,Helvetica,sans-serif }TH {font-family:Arial,Helvetica,sans-serif }TABLE {font-size:10pt;font-family:Arial,Helvetica,sans-serif }.style5 {
    color: #000066;
    font-family: "Times New Roman", Times, serif;
    font-size: 12;
    }
    .style6 {
    font-size: 12px;
    color: #333333;
    }
    .style7 {
    font-size: 14px;
    color: #000099;
    }
    .style8 {color: #FFFFFF}
    --></STYLE>
    </HEAD>
    <BODY BGColor=white>

    <Div style=width:600>
    <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>

    </TABLE>
    <TABLE cellSpacing=2 cellPadding=1 width="100%" bgColor=white border=0>
    <TR>
    <TD colSpan=2>
    <P class="style5 style7">&nbsp;For Your Picture To Be Used It <strong>MUST</strong>: <br>
    ..........1) Be Less Than 1.5mb (1,537kb). <br>
    ..........2) Be In A &gt;&gt;&gt;.gif,.jpg,.png,.jpeg,.bmp,.ico&lt;&lt; &lt; Format. <br>
    ..........3) Include Your Fist Name, The Year, And The Model. <br>
    ..........4) Be Good Quality <br>
    ..........5) Be A Chevy</P></TD>
    </TR>
    </TABLE>
    <hr size="3">
    <form name="file_upload" method="POST" ENCTYPE="multipart/form-data" OnSubmit="return ProgressBar();" Action="<%=PostURL%>">
    <Div ID=files>
    File 1 : <input type="file" name="File1" onchange=preview(this) onfocus=preview(this)>
    </Div>
    <input type="Button" name="Submit" value="Add A File" OnClick=return(Expand())>
    <span class="style6">&lt;&lt;&lt;Click &quot;Add A File&quot; To Upload More Than One Picture (Maximum Of 5)&lt;&lt;&lt;<br>
    </span><br>

    <table width="200" border="0">
    <tr>
    <td>Year:</td>
    <td><input type="text" name="CarYear" size="10"></td>
    </tr>
    <tr>
    <td>Model:</td>
    <td><input name="CarModel" type="text" id="CarModel" size="30"></td>
    </tr>
    <tr>
    <td>Email:</td>
    <td><input name="Email" type="text" id="Email" size="30"></td>
    </tr>
    </table>
    <br>
    <input Name=SubmitButton Value="**Submit **" Type=Submit>
    <br>
    </Form>

    <SCRIPT>
    function ProgressBar(){
    var ProgressURL
    ProgressURL = 'progress-limit.asp?UploadID=<%=UploadID%>'

    var v = window.open(ProgressURL,'_blank','toolbar=no,locat ion=no,directories=no,status=no,menubar=no,scrollb ars=no,resizable=yes,width=350,height=200')

    return true;
    }
    </SCRIPT>

    <Script>

    var nfiles = 1;
    function Expand(){
    if(nfiles < 5){
    nfiles++
    var adh = '<BR> File '+nfiles+' : <input type="file" name="File'+nfiles+'"onchange=preview(this) onfocus=preview(this)>';
    files.insertAdjacentHTML('BeforeEnd',adh);
    return false;}
    }
    </Script>
    <tr><td><Div ID=ImageName>Image preview :</Div></td><td>
    <img src=http://www.chevy-pics.doesntexist.com/pics/blank.jpg height="75" border=0 ID=ipreview>
    <br></td>
    </tr>
    <Script>

    function isImage(file){
    var ext = file.substr(file.lastIndexOf('.')).toLowerCase()
    return '<%=imageExts%>,'.indexOf(ext+',') >= 0
    };

    var lastfieldname = ''
    function preview(i) {
    var file = i.value
    if (file.length<=0) return;
    var ipreview = document.all('ipreview')
    if (isImage(file)) {
    ipreview.src = 'file://' + file
    ImageName.innerHTML = 'Image preview<br>(' + i.name + ')'
    } else {
    ipreview.src = 'res://shdoclc.dll/warning.gif'
    };
    lastfieldname = i.name
    }

    window.onerror = donotmsgboxes;
    function donotmsgboxes(msg,url,line)
    {
    return true
    }

    </Script>
    <br>
    <hr color=silver size=3>
    <CENTER>
    </CENTER>
    </Div>
    </BODY></HTML>

  2. #2
    Join Date
    Jan 2004
    Location
    India
    Posts
    31
    Hi

    I was too hasty to read all ur code, but i think u want ot upload files and paste some data in Text format.

    what i would suggest to use an free asp upload component

    http://www.freeaspupload.net/

    i am using it...it wrks fine :-)

    if u go fwd to use it, u can acces Your text fields as

    UpLoad.Form("YourTextField")

    tats all

    bye
    keep posted
    Attached Files Attached Files
    Do not walk behind me, for I may not lead.
    Do not walk ahead of me, for I may not follow.
    Do not walk beside me, either.
    Just leave me alone.

    Yogesh Jangam
    http://yogeshjangam.blogspot.com

  3. #3
    Join Date
    Dec 2003
    Posts
    454
    Post the code on line 39.

  4. #4
    Join Date
    Jan 2004
    Location
    NY
    Posts
    5

    Re: Please Help

    the code uploads a picture just fine but i want to also save whats in the text fields to a txt or access file. i tryed using request.form but thats giving me the error.
    Line 39 is

    OutputStream.WriteLine "Year: " + request.form("CarYear")

    i removed the pieces of code at were giving me the error. i included all the files as an attachment. i figured it would be easier to fix if you have the files.
    Attached Files Attached Files
    Last edited by ynk1121; 01-23-04 at 06:42.

  5. #5
    Join Date
    Feb 2002
    Location
    San Francisco, CA
    Posts
    441
    Use & not + to concatenate things with strings, + is maths stuff and can cause problems. Not sure if thats what is causing your problem, try it and see.

  6. #6
    Join Date
    Jan 2004
    Location
    NY
    Posts
    5

    Unhappy

    nope. i replaced the +'s with &'s and get the same error

  7. #7
    Join Date
    Dec 2003
    Posts
    454
    If you are using the object of ScriptUtils.ASPForm,

    Dim Form
    Set Form = Server.CreateObject("ScriptUtils.ASPForm")

    you need to use

    Form.Fields("FieldName")

    instead of

    Request.Form("FieldName")

  8. #8
    Join Date
    Jan 2004
    Location
    NY
    Posts
    5
    i tryed form.fields and it gave me
    error:
    Object doesn't support this property or method: 'Fields'

    im at the verge of giving up. i hate stupid computers :0(

  9. #9
    Join Date
    Feb 2004
    Posts
    2
    What ASP is trying to tell you is that you can't use request.form at all when doing a request.binary. I ran into this problem myself when trying to upload files and write information into Access. Here's the workaround:

    Create a form that gets the information (just the information without a file form field). Set this forms action to another ASP page where your'll convert the request.form information to session("") information. Redirect to another ASP form where you'll write the session information into form fields that look just like the original form, but now has a file form field. This way when you POST it will take the session information and put it to whatever you'd like and still perform the upload.

    If you didn't get what I'm saying, contact me and I'll walk you through it. I was banging my head against the wall with this one too.

    Bobbie

  10. #10
    Join Date
    Jan 2004
    Location
    NY
    Posts
    5
    yea, im lost. can you give a little more detail.
    thanks
    ~Brian

  11. #11
    Join Date
    Feb 2004
    Posts
    2
    Ok Create a new ASP page with your upload form. Don't add a file field to the form. Set the action of the form to changeinfo.asp.

    Changeinfo.asp will have the following code:

    session("id")=request.form("id")
    session("id2")=request.form("id2")
    {Keep adding the above lines with different form variagles until you're done.}
    response.redirect("uploadform.asp")

    Uploadform.asp can have a table that's set to mimick the look of the form. In the cells add <%=session("id")%> for each form variable to carry over. Add the file field now. Set the action to whatever you use to upload. To add the information to the database:
    {rs should be defined as the Server.CreateObject}
    rs.AddNew
    rs("fieldname")=session("id")
    {keep adding}
    rs.update
    conn.close
    set conn = nothing
    set sql = nothing

    That should help. Need more? Email me.
    Bobbie

  12. #12
    Join Date
    Jun 2003
    Location
    USA
    Posts
    1,032
    Just in case you need to switch to another uploading solution or look at how things are done here is another resource:

    ASP File Upload Using VBScript by John R. Lewis - 7/10/2000
    http://aspzone.com/posts/160.aspx
    J. Paul Schmidt, Freelance Web and Database Developer
    www.Bullschmidt.com
    Access Database Sample, Web Database Sample, ASP Design Tips

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •