Jump to content

Recommended Posts

You may ask "Why would you want to send a file with PHP instead of just linking to the file directly?" Simple answer: Download counter. I want to make a simple text file counter that will show me how many downloads my piece of software has received. What I want to do is to link to a PHP file that will add a hit to this simple text file counter and then route the browser to the file... but I have no idea how to do this. Is it possible to send a file as a browser would usually receive it instead of dumping it to the screen? And, while I'm at it, I DO want to change the MIME type of this file, so the browser recognizes it the way it should as I can't do this with my webspace provider.

 

So, here's the rundown for the sake of simplicity:

1. User clicks the link, which leads to a PHP file.

2. The PHP file adds a count.

3. The PHP file sends the file with the application/x-xpinstall MIME type.

 

Any way to do this?

Link to comment
https://forums.phpfreaks.com/topic/56827-send-file-with-php/
Share on other sites

If u r using db than its simple create an if statement where u have to put the download link, after that put

a query to insert record to db in that if statement.

I think it work, about flatfiles i have no idea,

Wait for someone who will try to help in flatfiles.

Link to comment
https://forums.phpfreaks.com/topic/56827-send-file-with-php/#findComment-280790
Share on other sites

You'd be better doing something like this:

 

download.php

 

<?php

// Update your counter here, depending on your preferred method

header("Content-type: application/x-xpinstall"); // Set the content type to the XPI install

readfile("myfile.xpi"); // Read the XPI file to be installed

?>

 

Untested, but give it a try :)

Link to comment
https://forums.phpfreaks.com/topic/56827-send-file-with-php/#findComment-280860
Share on other sites

Haha! Thank you! I had never heard of readfile() before. I'll look that up as soon as I get done jumping for joy! I thank you very much for all your help. I was wondering if that Content-Type header would stay after a redirect... and I guess it didn't. But it's all fixed now thanks to you! Take THAT stupid web host.

 

For the record I was NOT looking forward to reading the HTTP/1.1 standard, haha! But, if you have an idea what you're looking for, it's not so bad I guess.

Link to comment
https://forums.phpfreaks.com/topic/56827-send-file-with-php/#findComment-280862
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.