Additional .htaccess settings for Drupal

Here are some extra .htaccess commands to add to the standard Drupal setup Allow access for SSL LetsEncrypt.com If you are using LetsEncrypt, the default security stops access for folders starting with a period RewriteCond %{REQUEST_URI} “/.well-known/” RewriteRule (.*) $1 [L] Force SSL RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] Redirect to non-WWW RewriteCond %{HTTP_HOST} […]

Creating a file in the Drupal file system

This example shows how to create a file with a location within the Drupal file system. if (!isset($node -> uc_product_image[“und”][0])) { $filepath = “public://temp.jpg”; $data = file_get_contents($row[“frontcover”]); if (!empty($data)) { file_put_contents($filepath, $data); // echo “{$filepath}, “; $file = (object) array( ‘uid’ => 2, ‘uri’ => $filepath, ‘filemime’ => file_get_mimetype($filepath), ‘status’ => 1, ); $file = […]

Processing File Contents in Form Uploads

Suppose you want a form that allows the user to select a file. We want to upload that file and then process its contents. First define the file in the form definition function // File $form[‘file’] = array( ‘#type’ => ‘file’, ‘#name’ => ‘files[import]’, ‘#title’ => t(‘Choose a file’), ‘#description’ => t(‘Input file must be […]