post

HTTP Error when uploading images in WordPress – no thumbnail

Did you ever see HTTP Error when uploading an image in wordpress? Most of the times the images are uploaded but no thumbnail is created. And sometimes the images are not even uploaded. We are going to discuss about this right now!

There could be several issues that cause this error. First of all, we can assume that you don’t have enough memory for the script to be executed. So, try adding something like the following in your wp-config.php file:
[php]
define(‘WP_MEMORY_LIMIT’, ’64MB’);
[/php]

In stead of 64MB you may need more, though you can’t exceed the limit that your host allows you to use :)

If the solution doesn’t work, then open the .htaccess file from root of wordpress installation and add the following line:
[html]
AddType x-mapp-php5 .php
[/html]

Third issue could be mod_security is enabled in your server. To overwrite the default, create a .htaccess file in your wp-admin folder and paste the following code in there:
[html]

SecFilterEngine Off
SecFilterScanPOST Off

[/html]

Another main issue I suppose that your script is using ImageMagick library, but you need to use GD library to resolve the HTTP error. You need to force wordpress to use GD library in this case. To force you can use the following code:
[php]
add_filter( ‘wp_image_editors’, ‘force_to_use_GD’ );
function force_to_use_GD($array) {
return array( ‘WP_Image_Editor_GD’, ‘WP_Image_Editor_Imagick’ );
}
[/php]

I hope one of the above should fix your issue. There are more possible options out there though, but these are the common ones :)

post

How to get start date of a week in JavaScript

This is little tricky to get the start date or/and end date of a week. Also, there is no standard day that should be a REAL start day in a week. In my example, I assume that the start day is Monday. Also, I will show you how you can adjust it to fit your needs. So, you can make it as Saturday or Sunday or whatever.

In my example, suppose I want to make a title like “Accepting Bookings For the Week of START_DATE to END_DATE”. So, within this week, it should be same. But in next week, it should be changed automatically.

Well, it’s not hard, let’s look at the code:
[html]

Accepting Bookings For the Week of Feb 23rd to Feb 23rd

//
[/html]

There is some vita points. First month array, I needed to use that to print the month name as JavaScript has no function to print month name. So, when we will get the month number (0, 1, 2 etc) we will print the same index of month array. Note that getMonth() function returns the month number based on zero, so January would be 0, February would be 1 and so on.

Next one is:
[javascript]
startDate = d.getDate() – day + (day == 0 ? -6:1)
[/javascript]

This is where you need to edit if you change the start day. Change -6 to something between -1 to -7 and you will see the result.

And then the following line set the end date:
[javascript]
endDate = startDate + 6;
[/javascript]

If you want to make it for next week, then change this line
[javascript]
startDate = d.getDate() – day + (day == 0 ? -6:1)
[/javascript]

to

[javascript]
startDate = (d.getDate() + 7) – day + (day == 0 ? -6:1)
[/javascript]

And finally, I set the correct value in correct place:
[javascript]
document.getElementById(‘ds’).innerHTML = month[correctStartDate.getMonth()] + ” ” + correctStartDate.getDate();
document.getElementById(‘dl’).innerHTML = month[correctEndDate.getMonth()] + ” ” + correctEndDate.getDate();
[/javascript]

:)

post

Redirect to another page when back button is pressed in JavaScript

One of the most wanted feature now-a-days is to detect browser back button. Couple of years ago there were lots of script to detect browser’s back button, but browsers are getting smarter day by day, and so are we :)

Sometimes we need to redirect into a different page when user press browser back button. So, we need to detect when the user press back button. Well a developer Brooke Bryan wrote a script for detecting pressing back button. You will found the script here. But it will detect back button and then redirect to old page. I have modified the original code based on his suggestion so that you can set a script to redirect into a different page.

You can get modified script here:
[javascript]
/*!
* Back Button Detection Object V 1.0.1
* www.brookebryan.com/
*
* Copyright 2010, Brooke Bryan
*
* Date: Thu 27 Jan 2011 13:37 GMT
*/

var bajb_backdetect={Version:’1.0.0′,Description:’Back Button Detection’,Browser:{IE:!!(window.attachEvent&&!window.opera),Safari:navigator.userAgent.indexOf(‘Apple’)>-1,Opera:!!window.opera},FrameLoaded:0,FrameTry:0,FrameTimeout:null,OnBack:function(){alert(‘Back Button Clicked’)},BAJBFrame:function(){var BAJBOnBack=document.getElementById(‘BAJBOnBack’);if(bajb_backdetect.FrameLoaded>1){if(bajb_backdetect.FrameLoaded==2){bajb_backdetect.OnBack();}}bajb_backdetect.FrameLoaded++;if(bajb_backdetect.FrameLoaded==1){if(bajb_backdetect.Browser.IE){bajb_backdetect.SetupFrames()}else{bajb_backdetect.FrameTimeout=setTimeout(“bajb_backdetect.SetupFrames();”,700)}}},SetupFrames:function(){clearTimeout(bajb_backdetect.FrameTimeout);var BBiFrame=document.getElementById(‘BAJBOnBack’);var checkVar=BBiFrame.src.substr(-11,11);if(bajb_backdetect.FrameLoaded==1&&checkVar!=”HistoryLoad”){BBiFrame.src=”blank.html?HistoryLoad”}else{if(bajb_backdetect.FrameTry<2&&checkVar!=”HistoryLoad”){bajb_backdetect.FrameTry++;bajb_backdetect.FrameTimeout=setTimeout(“bajb_backdetect.SetupFrames();”,700)}}},SafariHash:’false’,Safari:function(){if(bajb_backdetect.SafariHash==’false’){if(window.location.hash==’#b’){bajb_backdetect.SafariHash=’true’}else{window.location.hash=’#b’}setTimeout(“bajb_backdetect.Safari();”,100)}else if(bajb_backdetect.SafariHash==’true’){if(window.location.hash==”){bajb_backdetect.SafariHash=’back';bajb_backdetect.OnBack();}else{setTimeout(“bajb_backdetect.Safari();”,100)}}},Initialise:function(){if(bajb_backdetect.Browser.Safari){setTimeout(“bajb_backdetect.Safari();”,600)}else{document.write(‘‘)}}};bajb_backdetect.Initialise();
[/javascript]

Now we need to use it.

Fortunately, you don’t need a second page to check this script. You will use this script in the page from where you need to redirect into a different page when back button is pressed. Logic is, when the page with the script loaded, a hashtag (#b) is automatically added with the URL. So, you can press the back button for the first page (as I said don’t need a second page to test).

I assume you have saved the above script in a file called – backfix.min.js and put it in js folder. So, first include the script into your html head section. And then call the script:

[html]

//
[/html]

And you’re done. You can do anything you want with script within that function. You also can set a message like “Are you sure want to live this page?” with confirm function.

So, Brooke made our life easy, Good bless him :)