Announcement

Collapse
No announcement yet.

A question from Web Developers!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    A question from Web Developers!

    salam
    ok ppl, my question is that how to force the web browser to initiate a file download (that save/open dialog box) programmatically from a server side script.
    for example, there are different users visiting a site, and now i want to send a user a particular file which could be written/ generated on the fly, means there is no link for the file like "http://www.mydomain.com/myfile.exe" the downloaded file could of any type

    i've tried the following asp script:

    PHP Code:
      dim fileToDownload
      dim outputString
      dim fso
      dim myFile
      fileToDownload 
    "test.exe"
      
    response.buffer=TRUE

    ' write header for application type
      response.ContentType="application/unknown"
      Response.AddHeader "Content-Disposition", "filename=" & fileToDownload

    open the file in text formate
      Set fso 
    createobject("scripting.filesystemobject")
      
    Set myFile fso.opentextfileserver.MapPath(fileToDownload), 1false)

    ' loop and write
       Do While Not myFile.AtEndOfStream
        outputString=myFile.readline
        response.write outputString & vbcrlf
       Loop

    close everything
       myFile
    .close
       set myFile
    =nothing
       set fso
    =nothing

    ' Flush everything in the buffer, thereby sending the file to the client.
       response.flush 
    when the script is called, it displays the desired dialog but when i open the downloaded file, it is corrupt , i tried bmp, and it came allll black, i tried exe, and when i run it opened that dos prompt window and terminated itself even the exe file downloaded was a valid windows application with a proper gui

    i know u will tell me to search it on web, i've tried a lil bit and found similar solutions

    can anybody plz tell me is there anything wrong with the above script which i'm using, the header the method of writing the file back to client or anything

    thnx in advance
    raheel
    Quwwat-e-Mazhab say mustehkam hay jami'yat teri

    #2
    hmmmm,

    why don't u want the user to have the flexibility to click the "file" which allows the download box to open rather than an automatic one?

    Comment


      #3
      Hehe, people have done some pretty wack things for that. Just put in a **** tag.
      Last edited by God : April 21st, 1987 at 09:23 PM.

      Comment


        #4
        Originally posted by khan_sahib:
        hmmmm,

        why don't u want the user to have the flexibility to click the "file" which allows the download box to open rather than an automatic one?
        u can say for security purpose or what if the file is a binary/ executable which is sold out to that person who has paid through a credit card!!!
        think of it this way now
        Quwwat-e-Mazhab say mustehkam hay jami'yat teri

        Comment


          #5
          Originally posted by RT Wolf:
          Hehe, people have done some pretty wack things for that. Just put in a **** tag.
          how???
          can u plz explain a bit
          Quwwat-e-Mazhab say mustehkam hay jami'yat teri

          Comment


            #6
            PHP Code:
            <**** **********="refresh" CONTENT="15;URL=http://www.domain.com"
            Just put that between your head tags.

            I believe that is it. the number 15 is the number of seconds before the page redirects.

            Hope this helps.
            Last edited by God : April 21st, 1987 at 09:23 PM.

            Comment


              #7
              Originally posted by RT Wolf:
              PHP Code:
              <**** **********="refresh" CONTENT="15;URL=http://www.domain.com"
              Just put that between your head tags.

              I believe that is it. the number 15 is the number of seconds before the page redirects.

              Hope this helps.
              oh thats great idea thank u very much RT Wolf
              but this keeps refreshing the page, i gotta do it with the help of javaScript

              thnx again
              Quwwat-e-Mazhab say mustehkam hay jami'yat teri

              Comment


                #8
                Originally posted by Aceones!:


                oh thats great idea thank u very much RT Wolf
                but this keeps refreshing the page, i gotta do it with the help of javaScript

                thnx again
                You're welcome! Sorry it ain't any help.
                Last edited by God : April 21st, 1987 at 09:23 PM.

                Comment

                Working...
                X