1

I've got a problem. I have two completely separate websites, one written in .Net using MVC2, the other written in PHP.

I have links in my MVC site to media files in my PHP site, and I'm trying to find a way to force a download when the user clicks these links.

How could I do this in MVC? I understand how I can return a FileResult like this:

 public FileResult Download(string path)
 {
        var contentType = "audio/mp3";

        FilePathResult result = new FilePathResult(Server.MapPath("~/Content/" 
                                                    + path), contentType);
        result.FileDownloadName = path;
        return result;
 }

But the Server.MapPath requires that the files be hosted on the MVC server.

Addendum

I also tried doing this on the .php side of the house, using a download.php?file=filepath and setting the content headers that way. However, I kept getting "Cannot modify header information - headers already sent" errors. I created a separate question on SO asking why this is happening.

Community
  • 1
  • 1
Slider345
  • 4,558
  • 7
  • 39
  • 47
  • *"Cannot modify header information - headers already sent"* errors are thrown when you try to modify header information **after** your application generated output. You need to make sure that you set your headers before any sort of output is generated by the application. – Telmo Marques Apr 17 '12 at 00:59
  • on the php front, the rest of the error says "(output started at download.php:1)" I've checked for whitespace before and after the script. That problem may be worthy of a whole separate question on SO. – Slider345 Apr 17 '12 at 01:15
  • There *are* already tons of separate questions about this: http://stackoverflow.com/search?q=Cannot+modify+header+information+-+headers+already+sent – deceze Apr 17 '12 at 01:46

0 Answers0