Tuesday, February 24, 2009

User Login Block customization - Drupal

You can use the following code in your block. I am using the casetracker module but you can modify your action destination accordingly.




uid) : ?>
name); ?> [ uid); ?> |
 ] 


Nama Pengguna :   Katalaluan :     Lupa Katalaluan?

Monday, February 23, 2009

Downloading Files From MySQL Database

When we upload a file to database we also save the file type and length. These were not needed for uploading the files but is needed for downloading the files from the database.

The download page list the file names stored in database. The names are printed as a url. The url would look like download.php?id=3. To see a working example click here. I saved several images in my database, you can try downloading them.

Example :



Download File From MySQL


$query = "SELECT id, name FROM upload";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty
";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))
{
?>




When you click the download link, the $_GET['id'] will be set. We can use this id to identify which files to get from the database. Below is the code for downloading files from MySQL Database.

Example :

$id = $_GET['id'];
$query = "SELECT name, type, size, content " .
"FROM upload WHERE id = '$id'";


$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);

header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;

include 'library/closedb.php';
exit;
}

?>

Before sending the file content using echo first we need to set several headers. They are :

  1. header("Content-length: $size")
    This header tells the browser how large the file is. Some browser need it to be able to download the file properly. Anyway it's a good manner telling how big the file is. That way anyone who download the file can predict how long the download will take.
  2. header("Content-type: $type")
    This header tells the browser what kind of file it tries to download.
  3. header("Content-Disposition: attachment; filename=$name");
    Tells the browser to save this downloaded file under the specified name. If you don't send this header the browser will try to save the file using the script's name (download.php).

After sending the file the script stops executing by calling exit.

NOTE :
When sending headers the most common error message you will see is something like this :

Warning: Cannot modify header information - headers already sent by (output started at C:\Webroot\library\config.php:7) in C:\Webroot\download.php on line 13

This error happens because some data was already sent before we send the header. As for the error message above it happens because i "accidentally" add one space right after the PHP closing tag ( ?> ) in config.php file. So if you see this error message when you're sending a header just make sure you don't have any data sent before calling header(). Check the file mentioned in the error message and go to the line number specified

Enjoy ubuntu.. ;)

Tq http://www.php-mysql-tutorial.com/

Uploading Files To MySQL Database

Uploading a file to MySQL is a two step process. First you need to upload the file to the server then read the file and insert it to MySQL.

For uploading a file we need a form for the user to enter the file name or browse their computer and select a file. The input type="file" is used for that purpose.

Example : upload.php
Source code : upload.phps

enctype="multipart/form-data">









An upload form must have encytype="multipart/form-data" otherwise it won't work at all. Of course the form method also need to be set to method="post". Also remember to put a hidden input MAX_FILE_SIZE before the file input. It's to restrict the size of files.

After the form is submitted the we need to read the autoglobal $_FILES. In the example above the input name for the file is userfile so the content of $_FILES are like this :

$_FILES['userfile']['name']
The original name of the file on the client machine.

$_FILES['userfile']['type']
The mime type of the file, if the browser provided this information. An example would be "image/gif".

$_FILES['userfile']['size']
The size, in bytes, of the uploaded file.

$_FILES['userfile']['tmp_name']
The temporary filename of the file in which the uploaded file was stored on the server.

$_FILES['userfile']['error']
The error code associated with this file upload. ['error'] was added in PHP 4.2.0


Example : upload.php

$_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}

include 'library/config.php';
include 'library/opendb.php';

$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

mysql_query($query) or die('Error, query failed');
include 'library/closedb.php';

echo "
File $fileName uploaded
";
}
?>

Before you do anything with the uploaded file. You should not assume that the file was uploaded successfully to the server. Always check to see if the file was successfully uploaded by looking at the file size. If it's larger than zero byte then we can assume that the file is uploaded successfully.

PHP saves the uploaded file with a temporary name and save the name in $_FILES['userfile']['tmp_name']. Our next job is to read the content of this file and insert the content to database. Always make sure that you use addslashes() to escape the content. Using addslashes() to the file name is also recommended because you never know what the file name would be.

That's it now you can upload your files to MySQL. Now it's time to write the script to download those files.

Enjoy ubuntu... :)

Tq http://www.php-mysql-tutorial.com/

Friday, February 6, 2009

Install RealPlayer in Ubuntu

1. Download RealPlayer
Go to http://www.real.com/linux and download the RealPlayer11Gold.bin file.

2. Make RealPlayer11Gold.bin file into an executable file.
Qoute : cd /home/kunkun/Desktop/download
Make the bin file into an executable file.
Qoute : chmod +x RealPlayer11Gold.bin

3. Run the bin file
Qoute : ./RealPlayer11Gold.bin
Accept the default values by pressing the Enter key.
By default, RealPlayer will be installed in /opt/real/RealPlayer

4. Setup RealPlayer
In the Application -> Sounds & Video -> RealPlayer 11
It will display the RealPlayer Setup Assistant. Just follow the setup instructions.

Enjoy ubuntu... ;)

Mailserver Postfix, Dovecot, Mysql dan Roundcube in Ubuntu

Mail virtual domain & virtual user : Postfix , Dovecot, Mysql , Postfix admin and Webmail Roundcube

Installing LAMP

Install a LAMP system. LAMP stands for Linux, Apache, MySQL, PHP. The guide is intended to help those who have very little knowlegde of using Linux.

  • Install Apache -> Qoute : apt-get install apache2

  • Install PHP -> Quote : apt-get install php5 libapache2-mod-php5

  • Installing MYSQL with PHP 5 -> Qoute : mysql-server libapache2-mod-auth-mysql php5-mysql

Install Postfix Dovecot:
Quote : apt-get install postfix postfix-mysql dovecot dovecot-common dovecot-imapd dovecot-pop3d libsasl2-modules-sql libsasl2-modules

Install postfixadmin:
Qoute : wget http://high5.net/postfixadmin/download.php?file=postfixadmin-2.1.0.tgz
Qoute : tar xvzf postfixadmin-2.1.0.tgz

Import database postfixadmin:
Qoute : cd postfixadmin-2.1.0
Qoute : mysql -u root -p < style="font-weight: bold;">
Configure
Postfixadmin:
1. Config file, create new file
Qoute : cp config.inc.php.sample config.inc.php
2. Edit config.inc.php
Qoute : gksu gedit config.inc.php
$CONF['postfix_admin_url'] = 'http://www.kunkun.com.my/postfixadmin';
$CONF['postfix_admin_path'] = '/var/www/postfixadmin';

$CONF
['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfix';
$CONF['database_password'] = 'postfix';
$CONF['database_name'] = 'postfix';
$CONF['database_prefix'] = '';
$CONF['encrypt'] = 'cleartext';

$CONF['domain_path'] = 'YES';

$CONF['domain_in_mailbox'] = 'NO';

Postfix:
Qoute : gksu gedit /etc/postfix/main.cf

myhostname = localhost
smtpd_banner = $myhostname ESMTP ready

alias_maps = hash:/etc/aliases
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_gid_maps = static:106
virtual_mailbox_base = /home/vmail
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_minimum_uid = 106
virtual_transport = virtual
virtual_uid_maps = static:106


broken_sasl_auth_clients = yes
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_non_fqdn_hostname,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unauth_destination,
reject_unauth_pipelining,
reject_invalid_hostname
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous

Sunday, February 1, 2009

Install Conky in Ubuntu

Conky is a free, light-weight system monitor for X, that displays any information on your desktop. Conky is licensed under the GPL and runs on Linux and BSD.

1. Install conky
Quote : apt-get install conky

Then, to see the result, enter alt + f2 then enter conky. Finish... ;)

If u want to display conky on desktop, follow this step.
1. Download : conkyrc
2. Then rename to .conkyrc
3. Move the new .conkyrc to your /home/kunkun/
4. Create new file
Quote : gksu gedit .conky_start.sh
5. Paste this code into .conky_start.sh
#!/bin/bash
sleep 10 && conky;
6. Save and exit
7. Then, Quote : chmod a+x .conky_start.sh
8. Then, System->Preferences->Session->Startup Srograms
Click add, then paste /home/kunkun/.conky_start.sh
9. Then Ok.
10. Done.

Enjoy ubuntu... ;)

kunkun-laptop .... ;)