Sunday, October 31, 2010

file upload in php example

Click the below link to download the code for file uploading

Click Here

php code to create thumbnail

Click the below link to download the code

Click Here

Wednesday, October 27, 2010

Simple wordpress widget

Take new php file then copy the below code to file and put the file in plugins folder and activate the plugin

Now you can see the widget in widgetarea of wordpress named 'My First Widget'

/* Plugin Name: Simple Widget */
function widget_myuniquewidget() {
echo "This is simple widget";
}
register_sidebar_widget('My First Widget','widget_myuniquewidget');

wordpress admin menu page

/* Plugin Name: Simple Admin Menu */

add_action('admin_menu', 'mt_add_pages');

function mt_add_pages() {
add_menu_page('Main Page','Main Page', 'manage_options', 'main-page-handle', 'main_page' );
add_submenu_page('main-page-handle','Sub Page1', 'Sub Page1', 'manage_options', 'sub-page1', 'sub_page1');
add_submenu_page('main-page-handle', 'Sub Page2', 'Sub Page2', 'manage_options', 'sub-page2', 'sub_page2');
}

function main_page() {
echo "Main Page";
}

function sub_page1() {
echo "Sub Page1";
}

function sub_page2() {
echo "Sub Page2";
}

Enable Htaccess in localhost

Open AppSer installed folder in that find conf folder and find httpd.conf file. In that file find below line(LoadModule rewrite_module modules/mod_rewrite.so)

For Example In Windows: D:\AppServ\Apache2.2\conf\

"LoadModule rewrite_module modules/mod_rewrite.so" if hash is there before the line remove that hash("#") or (";") symbol and save the file and restart the AppServer to work

Monday, October 25, 2010

Enable curl in php localhost Apache

Open your php.ini file and found the line 'extension=php_curl.dll' and remove the semicolon (; Here semicolon is comment). After that save the file and restart the apache server. You have done.

It is also helpful in future. Find the line 'extension=php_mcrypt.dll' and remove the semicolon before it if there. Save the file and restart the apache server.

php source code

you can download it from php.net/downloads.php

increase execution time in php

We can increase it in different ways based on server

Method 1: It will work in most servers. Add this function in top of page.
ini_set('max_execution_time', 600); //600 seconds

Method 2: We can set it by using .htaccess. Adding the below line in .htaccess file. It will work almost all servers.
max_execution_time 600

Method 3: If it is localhost. Open php.ini file and this word ('max_execution_time') where you can see like this by default max_execution_time = 30. You can change that 30 to your required based on your execution time for example (600) after that you have to restart the apache server.

Sunday, October 24, 2010

freelance job sites

www.odesk.com
www.guru.com
www.freelancer.com
www.ifreelance.com
www.getfreelancer.com
www.freelancers.net

many more are there.......

Create csv file in php

$data = "Id, FirstName, LastName, Email, Phone, ZipCode"."\n";
$data .= "1,'Test1','Test2','Test@gmail.com','546435','10001'"."\n";

$myFile = "userinfo.csv";
$fh = fopen($myFile, 'a') or die("can't open file");
fwrite($fh, $data);
fclose($fh);

Saturday, October 9, 2010

difference between curl and file_get_contents

file_get_contents - It is a function to get the contents of a file(simply view source items i.e out put html file contents).

curl - It is a library to do more operations, for example get the contents like file_get_contents, sending and receiving data from one site to another site and it also supports different types of protocols like http, https, ftp, gopher, telnet, dict, file, and ldap. curl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading HTTP form based upload, proxies, cookies.

You can read more about these in http://php.net/