PHP bug when uploading Word or Excel files to WordPress

If you’re unable to upload docx or xlsx files to WordPress due to “Sorry, this file type is not permitted for security reasons”, it may be down to this PHP bug. The MIME type of the file is reported incorrectly.

The bug seems to apply to PHP 7.3 upwards, and is not currently fixed. Here’s a workaround you can drop into functions.php:

function fix_office_file_mimetype_bug( $compact, $file, $filename, $mimes ) {
  if (strpos($filename, '.docx') !== false) {
    $finfo     = finfo_open( FILEINFO_MIME_TYPE );
    $real_mime = finfo_file( $finfo, $file );
    finfo_close( $finfo );

    if ($real_mime == 'application/vnd.openxmlformats-officedocument.wordprocessingml.documentapplication/vnd.openxmlformats-officedocument.wordprocessingml.document') {
      $compact['ext'] = 'docx';
      $compact['type'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
      $compact['proper_filename'] = $filename;
    }
  }

  if (strpos($filename, '.xlsx') !== false) {
    $finfo     = finfo_open( FILEINFO_MIME_TYPE );
    $real_mime = finfo_file( $finfo, $file );
    finfo_close( $finfo );

    if ($real_mime == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheetapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
      $compact['ext'] = 'xlsx';
      $compact['type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
      $compact['proper_filename'] = $filename;
    }
  }

  return $compact;
}
add_filter( 'wp_check_filetype_and_ext', 'fix_office_file_mimetype_bug', 10, 4 );

Laser surgery

I had laser eye surgery this afternoon. It was a bit magical.

Nothing was wrong: it was elective. I’ve been short-sighted since I was 10, but for the last 15 years my vision’s slowly been getting better. I was due to reach perfection in the next couple of years, then sail right through it into long-sightedness. I was improving fairly quickly so was perpetually out of focus in one eye or the other, and lockdown seemed a good time to sort this.

So today I slid under a large machine and was told to stare at a green light while the LASIK surgery worked its wonders.

If you squick about eye stuff, skip to END OF SQUICK.

****SQUICK*****

They cut a FLAP in my CORNEA. This was an unusual thing to witness. It wasn’t painful, due to anaesthetic drops, but I could feel it happening and it was certainly uncomfortable. This took twenty seconds of staring at a precision laser while my eye was held open with tape and a speculum (and a surprising lack of head restraint). There were some weird visual effects: I saw red, blue and green sparkles that are hard to describe: the best I can get is ‘dead-pixel fireflies’. They were beautiful, though, and I can’t imagine I’ll see them again. This was followed by the usual apparitions you get when you rub your eyes, just a lot more eldritch.

Then they LIFT THE FLAP and fire a different laser. Let me tell you, watching somebody lift up the front of your eye is a good addition to the qualia bank. Everything went fuzzy and an invisible laser spent 4 seconds reshaping my lens. You’re meant to keep staring upwards but in all honesty heaven only knows what was going on at this point – I had sensations of being something akin to cross-eyed, entirely outside of conscious control. I just concentrated on looking in the correct direction. This whole thing was painless, and I wouldn’t have known the laser was firing if the surgeon hadn’t kept me informed.

Then that’s it. Flap down and smoothed over with tiny brushes. More drops.

****END OF SQUICK****

And then the same for the other eye. Bish bash bosh. Whole thing took 10 minutes.

I sat up, and things were foggy but…sharp. I walked out of the room, mildly dazed but fine. 5mins later the surgeon tested my vision with your basic letters on a chart, and said I already had 20:20 vision. 5mins later I was in a taxi.

It’s now 7 hours later, and things are good: a little foggy, but I can see unaided for the first time in 25 years. The fog should clear by morning. My brain refuses to parse good sight + gritty-feeling-in-eye as anything other ‘you need to take your contact lenses out’. I’m having to override that every ten minutes. It might take my subconscious a while to catch up, there.

I have a plethora of drops for the next week, a supply of artificial tears for the next couple of months, plus 2 checkups and strict instructions to avoid dusty environments / bright light / poking myself in the face. As far as I can tell this is all about making sure the aforementioned incision heals ok.

I am in awe that it is possible, as a matter of routine, to fire lasers into people’s eyes and fix their sight. In an hour. I didn’t even take my coat off.

Brandi Carlile

Me playing Spotify artist-radio during lockdown:

Me: Who’s this?! It’s great
Spotify: It’s Brandi Carlile
Me: What about this?
Spotify: Another Brandi Carlile
Me: Ok but this is definitely someone else and it’s excellent
Spotify: Still her
Me: Wh…
Spotify: Just go listen to her albums

Turns out I really like Brandi Carlile. You might too, if you like country but not, like, heavy country.

If you like The Story, you’ll probably enjoy everything else.

Only country singer I’ve ever heard mention skeptics, too.

Back to blogging

Hey. It’s been a while.

If you’ve come over from my old blog: this is a fresh start. All the old posts are now private, because I can’t face hunting for dumbass opinions in 4000 posts from my 20s.

The blog died out because Twitter and Facebook took over. But it feels like time to make something of my own again.

I still like Twitter, despite the obvious. I follow a bunch of delightful people. Most days I can log on and see lovely things. I’m not interested in broadening my bubble by following people who aren’t lovely.

But, like the blog, the day is coming when I’ll need to scrub my past tweets. I have 12 years of them, and no doubt some could come back to cancel me. I have enough seniority at work now that this would cause problems. If I were sensible I’d install the app that scrubs tweets on a 2 week rolling basis.

Certainly Twitter is no longer the place to store thoughts I want to keep. Ditto Facebook. I still like Facebook too. I enjoy seeing my friends’ baby photos and holidays and thoughts and worries. I just unfollow anybody ranty.

Facebook is also important. It’s such a part of the cultural landscape that IT people should know what’s going on. Plus, who am I kidding – it’s nice to get engagement! And Facebook is obviously very good at engagement. I’ve been using Facebook for little blog posts for a while – it’s a good way to share tech advice with non-techie people and I like getting the feedback and reactions. I’m not fond of reducing nice things to dopamine hits and declaring them bad.

But, let’s face it, one day Facebook are going to do something beyond the pale. Many would claim they already have, although those roads often lead to Cadwalladr and nobody wants that.

So: back to blogging, where I have more control. And after all these years I still like playing with WordPress.

In particular, I want to understand Gutenberg better. At the start of lockdown this led to a brief flirtation with front-end javascript frameworks like React and Vue, moving onto Gatsby and other static site generators.

That didn’t last long. JS has tentacled such that it’s inaccessible to broad-spectrum IT guys like me. I’ll figure out enough to understand Gutenberg, and leave it at that. WordPress and PHP it is.

I have a few life things coming up that I’d like to document. Some photo stuff. And there’s a lot of niche knowledge of work tools – CiviCRM in particular – that I’d like to make public.

So, hey. Nice to be back.