Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To be completely secure, you'll need to do a couple of things:</p> <p><strong>Set your upload directory above your "public" folder, making it inaccessible from a browser.</strong> This setting is in php.ini (php config file). You'll need to restart Apache for this to take effect. On most Redhat / Fedora / CentOS web servers, this can be:</p> <pre><code>upload_tmp_dir = "/var/tmp/" </code></pre> <p>OR, on my local Windows 7 WAMP install, it is set to:</p> <pre><code>upload_tmp_dir = "c:/wamp/tmp" </code></pre> <p><strong>Disable scripts from running on that directory (c:/wamp/tmp), in .htaccess:</strong></p> <pre><code>RemoveHandler .php .phtml .php3 RemoveType .php .phtml .php3 php_flag engine off </code></pre> <p><strong>In your PHP script, get the uploaded file, filter it based on mimetype (not filetype extension), change the filename, and put it into a secured publicly accessible folder.</strong> In more detail:</p> <ul> <li>create a whitelist of filetypes, ex: only images (jpeg, png, gif, bmp). This can be done using <strong>mime_content_type()</strong> <a href="http://php.net/manual/en/function.mime-content-type.php">http://php.net/manual/en/function.mime-content-type.php</a> or the newer <strong>finfo_file()</strong> <a href="http://us3.php.net/manual/en/function.finfo-file.php">http://us3.php.net/manual/en/function.finfo-file.php</a> </li> <li>choose a new filename, often it's best to use a random MD5 hash based on the original filename + salt + timestamp.</li> <li>move it to a public folder, ex: "c:/wamp/www/project_name/public/uploads"</li> </ul> <p><strong>Preferably use an MVC framework, such as Zend Framework, which includes filetype filtering.</strong></p> <p>If you do all of that, you should be secure. Obviously you'll never be 100% safe, since there are countless obscure exploits targeting PHP, MySQL, the command line, etc, particularly on older systems. On larger company webservers (what I work on), they disable everything, and selectively enable only what is required for the project. With a system such as WAMP, they enable everything, to ease local development.</p> <p>Good practice for working on a professional project is to get a cloud server account with Rackspace or Amazon, and learn how to configure php.ini, and httpd.conf settings, as well as PHP security best practices. In general, do not trust the users input, expect it to be corrupt / malicious / malformed, and in the end you'll be secure.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload