I'm thinking of saving uploaded docs to a folder outside the webroot and feeding the downloads with a script using readfile(file)
.
However, I'm wondering if the the following would be enough to remove any kind of threats there could be:
$filename = basename($_FILES['uploaded_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "doc") && ($_FILES["uploaded_file"]["type"] == "application/msword"))
{
execute rest of the code
}
I've read people recommended using finfo_open()
, but my server is under php 5.3.0 so I can't use it. I've tried using mime_content_type()
but it will always throw me a "text/plain" with any kind of file I send through (I don't know if I'm doing something wrong with that).
Is there anything I could add to make this a more secure process?
In the Documents area, click New Document and then click Upload Existing File. Tips: You can also drag or drop files or save directly to your team site or OneDrive for Business from Office.
Google Docs is a free, web-based alternative to Microsoft Word. All you need is a Google account, an internet connection, and these tips and tricks.
Chances are that your document is set to update styles from the template upon opening. You need to change this setting. Go to the Developer tab and click on Add-Ins. If "Automatically update document styles" is checked, uncheck it.
One issue you will inevitably come across is that browsers can tag a file's mime-type inappropriately. For example there is a common Firefox bug that can tag most files as application/octet-stream even though the file genuinely is a doc or pdf, or xls file, etc. The 'safest' thing to do is scan the file server side, which should also include a virus check. However if you have limited server access you may not be able to do this.
I've used ClamAv (http://www.clamav.net/lang/en/) in the past to do this.
See http://sourceforge.net/projects/php-clamav/ for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With