I've written a PHP script that handles file downloads, determining which file is being requested and setting the proper HTTP headers to trigger the browser to actually download the file rather than displaying it in the browser. I now have a problem where some users have reported certain files being identified incorrectly so regardless of extension, the browser will consider it a GIF image. I'm guessing this is because I haven't set the "Content-type" in the response header.
Is this most likely the case? If so, is there a fairly generic type that could be used for all files, rather than trying to account for every possible file type? Can anyone identify the bottleneck that is causing this? As explained by Alex's link you're probably missing the header Content-Disposition on top of Content-Type. You can try this force-download script. Even if you don't use it, it'll probably point you in the right direction:. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. You also need to be aware of the HTTP response headers that affect file downloads. A dialog is displayed allowing the user to save the file locally:. The trouble is that the browser behaves differently if the file is something that it can display itself.
The header also allows you to control the default file name. For static content you can manually configure the additional header in your web server.
Thank you! Comments are closed for this post. Something to add? Let me know. Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience.
Here you will find posts about web development, WordPress, security, and more ». To organize my life, I keep it simple. Official list of Googlebot IP addresses.
I enjoy listening to original Star Trek and NG episodes while working online. New version 2. The function download. Support for method "libcurl" is optional on Windows: use capabilities "libcurl" to see if it is supported on your build.
There is support for simultaneous downloads, so url and destfile can be character vectors of the same length greater than one but the method has to be specified explicitly and not via "auto". For methods "wget" and "curl" a system call is made to the tool given by method , and the respective program must be installed on your system and be in the search path for executables.
They will block all other activity on the R process until they complete: this may make a GUI unresponsive. It is used by available.
The "wininet" method supports some redirections but not all. For method "libcurl" , messages will quote the endpoint of redirections. Most methods do not percent-encode special characters such as spaces in URLs see URLencode , but it seems the "wininet" method does. The remaining details apply to the "internal" , "wininet" and "libcurl" methods only. The timeout for many parts of the transfer can be set by the option timeout which defaults to 60 seconds.
0コメント