How to disable comments notification for WordPress

Do you receive alot of emails sent by your WordPress Blog becouse people comment your posts?

You can turn this off like this:

1. Login to your blog admin page

2. Click on Settings -> Discussion

3. Search in that list for “E-mail me whenever:”

Now by default you receive email when “Anyone posts a comment” and “A comment is held for moderation“. Uncheck any or both of this options as you like.

You should definitely uncheck “Anyone posts a comment”.

Tags: , ,
Posted in Wordpress by admin. Comments Off

$_FILES limitation when uploading files in PHP

Along with the “upload_max_filesize” when uploading files with PHP there is another parameter named “max_file_uploads” witch prevent uploading more files that the value of this parameter.

Default size of this parameter is 20 and is should be enough for more apps then I can count but today I had to repair a bug in a page where a form contain 30 file uploads and just 20 were availble in $_FILES from php script.

How can you change this?

There are 2 methods. One is to change it from php.ini but not always you can access php.ini file

The second method is not using ini_set :( . Tried that and not working.

I did find another method witch need some javascript. The method is when submiting the form a javascript will disable all unused upload elements like this:

  1. jQuery("#upload_files1").submit(function(){
  2.     jQuery(‘input:file[value=""]‘).attr("disabled", true);
  3. });

and the form:

  1.  
  2. <form id="upload_files1" enctype="multipart/form-data" method="post">
  3. <input name="img[]" type="file" />
  4. <input name="img[]" type="file" />
  5. <input name="img[]" type="file" />
  6. <input name="save" type="submit" value="Save" />
  7. </form>
Tags: , , , , ,
Posted in jQuery PHP & MySQL by admin. Comments Off

7pic – the new free photo hosting service

I had stumbled today on 7pic.com website witch is a new and free hosting service for photo sharing. I give it a try and I like it becouse i can use the 7pic uploader to upload picts without to start a browser.

Uploaded images are stored in albums and can be shares as an images witch can be embedded in a blog post or as a link to a page on 7pic.com where anybody can comment that images share on facebook, twitter and other social networks and of course anybody can rate the picture.

 

Tags: , ,
Posted in Websites & Web services by admin. Comments Off

How to use call_user_func_array with a simple function and with class methods

In this post you will see a example of using call_user_func_array (from PHP) to call a simple function, a public static method from a class and a public method.

First I define one function and one class:

  1. function add($p1, $p2){
  2.    return $p1 + $p2;
  3. }
  4.  
  5. class CSimpleMath{
  6.    function __construct($v1) {      
  7.    }
  8.  
  9.    public static function multiply($a, $b){
  10.       return $a * $b;
  11.    }
  12.  
  13.    public function substract($a, $b){
  14.       return $b$a;
  15.    }
  16.  
  17.    function __destruct() {            
  18.    }   
  19. }

Maybe you notice that in the class I did inserted a construct and destruct functions. You dont realy need them for this example to work but I always include them when I write a class.

Call a simple function with call_user_func_array:

  1. echo call_user_func_array(‘add’, array(2, 5));

Call a public static method:

  1. echo call_user_func_array(‘CSimpleMath::multiply’, array(2, 5));

Call a public class method

  1. call_user_func_array(array(‘CSimpleMath’, ‘substract’), array(2, 5));
Tags: , , , , ,
Posted in PHP & MySQL by admin. Comments Off

“Progress bar” for long running cron scripts in PHP

Long running scripts can be a pain if you dont know how much will be running. If you need to see a progress and flush() or ob_flush() do not work becouse of browser cache you can implement an “email progress bar”.

PHP example:

  1. $step = 0;
  2. $last_percent = 0;
  3. $total_rows =
  4. while(1) {
  5.    $step++; //count step
  6.  
  7.    // here should be is the code witch consume time for every loop
  8.    // end consuming time code
  9.  
  10.    $procent = ($step * 100) / $total_rows;
  11.    if ($last_percent != round($procent)){
  12.       // becouse you do not want to receive an email for every step
  13.       $last_percent = round($procent);
  14.       if (($last_percent % 10) == 0){  
  15.          // this will send email from 10 % to 10 % – total 10 emails
  16.          mail(your_email_here, ‘Progress ‘.$last_percent.‘% done’ , "Progress: ".$contor."/".$total_rows);
  17.       }
  18.    }
  19.  
  20. } // end while

As you can see the ideea is very simple and you can implement it in any language.

Tags: , , , ,
Posted in PHP & MySQL Website's by admin. Comments Off

Apple spy your iOS 4 iPad and iPhone

If you want to see what Apple will know about you on your next device sync look for file consolidated.db and open it with a sqlite application or watch it sync over a map with the free application iPhoneTraker (just for MAC users)

Tags: , , ,
Posted in Apple iPad iPhone iPhone Apps by admin. Comments Off

Prevent Firefox to load css/js from cache

This days I was working on a webpage but to test in Firefox was a pain. Firefox store css and js in cache with the rest of the page. Reloading page with CRTL + F5 combination seems to reload from server the page but not the css/js files. After hours of frustration and complete cache delete before every page test I did found 2 methods to prevent Firefox to cache.

First and the easy one is to enter in the about:config menu (if you do not know what I mean by about:config go to Firefox url box paste about:config and press <enter>. You will find there settings you will not find in the firefox menus).

From the about:config search  network.http.use-cache and set it to false. This will force Firefox to stop loading pages from cache (this will slow your firefox).

The second method to prevent caching (and this method is working for all browsers) is to load the js / css like this

  1. <!– style loading –>
  2. <link rel="stylesheet" type="text/css" href="style.css?<?=rand(0, getrandmax()); ?>" />
  3. <!– js loading –>
  4. <script src="xxx.js?<?=rand(0, getrandmax()); ?>" type="text/javascript"><!–mce:0–></script></link>

The second method is availble just for developers

Posted in Other by admin. Comments Off

How to replace substring in MySQL table field

This replace will search in every row of the table where condition from WHERE is true and replace function will replace all instances in a string.

ex. if you have text “hello world” and you want to replace the “o” letter with “*” this will will transform the text in “hell* w*rld”

  1. UPDATE `mytable`
  2. SET my_content = REPLACE(content, ‘substr_string_to_replace’,‘the_new_string’)
  3. WHERE INSTR(content, ‘substr_string_to_replace’) > 0;
Tags: , , , ,
Posted in PHP & MySQL by admin. Comments Off

PHP: trim spaces in the middle of a string

When you let users input text in a textfield or input box iti is always a good ideea to use trim function to remove spaces form the begining or the end of the string.

Today I needed a function to trim spaces from the middle of a string and replace with a single space.

  1. /*
  2.     this will return the string where groups of consecutive spaces
  3.     are collapsed in a single space
  4.    
  5.     eg. $str = "This is    my test    string";
  6.     function will output "This is my test string"
  7.  */
  8. function centerTrim($str){
  9.     return preg_replace("/\s+/", " ", $str)
  10. }

if you need to remove all spaces you can use this function:

  1. /*
  2.     eg. $str = "This is    my test    string";
  3.     function will output "Thisismyteststring"
  4.  */
  5. function centerTrim2($str){
  6.     return preg_replace("/\s+/", "", $str)
  7. }
Tags: , , ,
Posted in PHP & MySQL by admin. Comments Off