Jump to content

Best way to send files to client


sylvest

Recommended Posts

I have a requirement for my PHP pages sometimes to send files (e.g. images, CSS files, JS files, fonts) to the client. The normal way to do this seems to be to use the readfile() function, but I understand that this reads the whole file into memory and then sends it to the client, which will cause problems if it is a very large file. I understand that there is an Apache module mod_xsendfile which does a better job, but Support tell me that this is not available on my shared server. So my question is, what is the best/most efficient way of sending files to the client in PHP, without mod_xsendfile? Do I have to write a loop that reads the file a few K at a time and sends each chunk to the client before reading the next?

If so, has anyone got this code already working that they would be happy to share with me, to save a bit of time?

Thanks - Rowan

Link to comment
Share on other sites

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...