-1

I am new to PHP. I have a software downloads website. What I want is to automatically add "-mysite.com" with every download filename. So that the actual filename remain the same i.e "somesoftware.exe" but whenever someone download it, it should be automatically renamed and downloaded with the filename "somesoftware- mysitename.com.exe" to their computer. Here is the code for download link div on my site.

    <!--===========================Download Div===============================-->

     <div id="downlink-container">
     <a href="http://www.mysitename.com/downloads/jetaudio16.0.0.435-mysitename.com.exe" id="downloadlink" style="visibility:visible">
      Download Jet Audio
     </a>
     </div>

     <!--===========================Download Div====================================-->

Can I use PHP to automatically add "-mysitename.com" with the downloaded file name "somesoftware.exe" so that the actual filename on server folder remain the same(i.e. somesoftware.exe) but whenever someone download it, it automatically become "somesoftware- mysitename.com.exe". I tried using PHP variables for this but I can't get it done. Please Help!

Naeem Ul Wahhab
  • 2,465
  • 4
  • 32
  • 59

2 Answers2

1

You set the following header:

header('Content-Disposition: attachment; filename="downloaded.pdf"');

Where downloaded.pdf is your filename. Its just a matter of getting the extention and adding "- thenoblesite.com" to the original name.

Kevin Vandenborne
  • 1,397
  • 1
  • 10
  • 28
1

Once user starts downloading a file, it's over - you have no control over it, no PHP, no anything. So the idea is to either rename the source file (which you don't want) or to actually stream the file using a different name. See it here.

Shomz
  • 37,421
  • 4
  • 57
  • 85