2

I have a text file and want to download it. I am working in localhost. The HTML page from which I am downloading file, is called from localhost:8080. And the file which I want to download, I am calling using another port i.e. 'localhost:100'.

If I do like this I am not getting that particular txt file, in fact the whole location of the of the folder is getting downloaded in HTML format. How to resolve this issue ?

But when the port is same for both HTML and the download URL , that particular text file is getting downloaded.

EDIT

HTML Page (http://localhost:8080/project/test.html)

    <HTML>
    <HEAD>
    <script src="//code.jquery.com/jquery-1.9.1.js"></script>
    <script type="text/javascript">
        var url="http://localhost:100/test";
        var file = "test112.zip";
        saveFile(url,file);  // Text Document
        alert("File is downloaded");

        function saveFile(fileURL,fileName){

             if (!window.ActiveXObject) {
            var save = document.createElement('a');
            save.href = fileURL;
            save.target = '_blank';
            save.download = fileName || fileURL;
            var evt = document.createEvent('MouseEvents');
            evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0,
                false, false, false, false, 0, null);
            save.dispatchEvent(evt);
            (window.URL || window.webkitURL).revokeObjectURL(save.href);
            }        
        }

    </script>
</HEAD>
<BODY>

</BODY>
</HTML>

When this runs following file gets downloaded -

download.html

In download.html there is

Index of /test

The localhost:8080 is Jetty Server and localhost:100 is Apache Server

1 Answer 1

1

You need to make sure that both servers have the exact same document root folder defined in the configuration files. In a fresh install of apache, look at httpd.conf and find contents similar to this:

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/path/to/html"

And change:

/path/to/html

to the folder the text file is in.

You will then need to restart the web servers that you changed the configuration files of.

If you still have trouble, check error logs of each web server to see what folder each one is actually trying to access. You will want to look for status 404 errors as those mean "not found".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.