If you’ve for whatever reason noticed that your WordPress website is generating errors similar to the following then I may have a solution for you.
Warning: getimagesize(/home/.some-dir/example.com/folder/httpd.www/wp-content/uploads/some-image.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/.some-dir/example.com/folder/httpd.www/wp-content/blah/blah/blah.php on line 123
I noticed that some pages that generated image information were printing errors out on my pages with private server file structures included. Generally you don’t want to see this printed out to the public. 😉
I’m not guaranteeing a fix for you, but rather what worked for me.
If you are getting an error link the one that I’ve listed above, more specifically the “failed to open stream: No such file or directory,” then you may be about to fix it in only a few minor steps.
Things you will need:
- FTP (I use FileZilla)
- Ability to add a new plugin to your site
Single quotes must be the normal ascii quotes. Chances are, if you copy and paste from my blog, they will be the wrong type so double check that as it could give you problems. 😉
- First and foremost, make sure to backup your entire database to a safe place. I’m not liable in the case that you don’t backup your database and this procedure borks your blog (or any other case for that matter). 😉
- Create a new file named “abstest.php” and upload it to your blog’s root directory after entering the following code into it:
<?php define('ABSPATH', dirname(__FILE__).'/'); echo ABSPATH; ?>
- Open a new browser tab and navigate to “http://www.your-website.com/abstest.php“. You should find a short page with the printout of your servers absolute path.
- Check that the path provided by this test file matches the base path printed out by the getimagesize() error exactly. In my case, my server had changed slightly so the differences were similar to the following:
- If you find a mismatch, then you’ve found your problem and the rest is simple. If not, then my tips will most likely not solve your particular WordPress error(s).
- If you’ve found a mismatch, then continue: Open a new browser tab and navigate to your phpMyAdmin interface. Select your WordPress database, then click Search. I searched all tables for a match of the path that was different, in my case it was “.some-dir/“.
- If there are matches found then you need to click the SQL tab at the top (preferably in a new tab) and paste the following (making sure to edit it to match the table and fields you need) and run it to find and replace that changed part of the path.
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);
For more information on SQL find and replace, either search Google or read this.
- After replacing all of the affected tables and strings, your images should be properly address. You’re not done yet though.
- Open WordPress Plugins and add/install a plugin named “Regenerate Thumbnails“. After installing it, make sure to activate it. 😉
- In your Admin panel, find the Tools menu and expand it. You should see a menu item labeled “Regen. Thumbnails”…click it. This will open a page with a start button. Clicking this button will begin the process of correcting your thumbnail dimensions as well as other metadata. It will take some time depending on the number of thumbnails you have accumulated.
- After the progress bar reaches 100% it will notify you that it is complete. You’re all done! You may need to clear your cache to refresh any pages that still generate the previous error message.
If you had any problems with the above mentioned procedure, I would suggest restoring your database using your backup copy and either trying again, paying someone to do it for you or just forgetting about it. 😉
If it works then great! If not then sorry you’ve wasted your time. It worked for me, so maybe it will work for you as well. 😀