Qmail send conflict with google apps SMTP

June 10th, 2011 by sonal.shah § 3

Recently I have faced one issue during server transfer.we needed to transfer server from shared to dedicated.this dedicated server was having parallel plesk control panel,which has by default qmail-send program enabled for mail sending. we choose google apps SMTP server for mail send.

Now Issue we encountered was as below :
In Our Site,Two e-mails are sent when filling out our “Contact Us” form.
(1) One E-mail sent to the person who filled out the form
(2) A copy of the inquiry is sent to [email protected]
1st was working fine,but 2nd was not working..we were not receiving any mails on [email protected]

every time we were getting failure notice,while sending mail to [email protected]

It was like below :

‘Hi. This is the qmail-send program at mysite.com.
I’m afraid I wasn’t able to deliver your message to the following addresses.
This is a permanent error; I’ve given up.
Sorry it didn’t work out. : This address no longer accepts mail. ‘

Solution of this issue is as below :-

For Mail Purpose, we were using google apps SMTP server which means external MX-record was enabled,
while parallel plesk control panel has by default internal MX-record service was enabled.

we can not have 2 MX-records enabled at the same time.
so we need to disable internal MX-record.so we disabled mail service from PPP(parallel plesk panel) and all started to work properly!!!.

Paypal shopping cart integration using HTML for Beginners

November 9th, 2009 by devdatt.mehta § 12

In online payment paradigm Paypal is one of the best and popular online payment services. Through this article I will share my experience with you about integration of online payment services.

Novice developer may find this post very useful.

I have used following methods for the online payment integration in my shopping cart.

In development process you need to create paypal testing account for that create paypal sandbox account for the testing purpose.

Step 1: https://developer.paypal.com/
Step 2: Create new account
Step 3: Paypal will send you activation link in your email inbox.
Step 4: Login in sandbox
Step 5: Create Test Accounts for buyer and seller accounts

Go to the Test Account page in paypal. Basically you need to type of account for your site integration
1.Buyer Account
2.Merchant Account.

Select country “United States”.
If you want to create buyer account choose Account Type: Buyer
Fill the form accordingly. Keep your login and password some where.
Click on “Show Advanced Options”.
Choose what card you want to use when will do online purchase for testing.
Set Account Balance.

Create seller account in same way as above.

Paypal gives you many ways to integrate your site with but here I will explain one method for the integration.

Simple Integration
==================
In simple integration with your site you need to know some predefined html variable created by paypal.

Not all the HTML variables I shown here but some of the important that I showed here out of other it is depend on your merchant account and situation.

Ref: https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables

set following html variable as hidden in your Buy Now button page in your shopping cart page.

Replace all the value as per given instructions under the value attribute.
<FORM name=”redirectoPaypal” METHOD=”POST” ACTION=”https://www.sandbox.paypal.com/cgi-bin/webscr” />
<INPUT TYPE=”hidden” name=”CMD” value=”_xclick” />
<INPUT TYPE=”hidden” name=”amount” value=”shopping cart total amount of selected items” />
<INPUT TYPE=”hidden” name=”item_name” value=”shopping cart item description or name” />
<INPUT TYPE=”hidden” name=”item_number” value=”selected item number” />
<INPUT TYPE=”hidden” name=”quantity” value=”selected item quantity” />
<INPUT TYPE=”hidden” name=”currency_ code” value=”USD” />
<INPUT TYPE=”hidden” name=”invoice” value=”invoice number” />
<INPUT TYPE=”hidden” name=”business” value=”your merchant paypal login id” />
<INPUT TYPE=”hidden” name=”return” value=”site url for success page” />
<INPUT TYPE=”hidden” name=”cancel_return” value=”site url for cancel paypal payment page” />
</FORM>

more explanation of html variables.
“CMD” is use for shopping cart do not change it.
“business” in testing set seller account id here after complete testing change to real merchant account id.
“return” is page url of your site paypal will redirect on this page with some extra variable such as transaction id. just debug with var_dump($_GET)
and use.
“cancel_return” is page url of your site. paypal will redirect on this page if user will denied to confirm the payment.

put above code in your page and test it.
when your set-up working successfully. change the action url to “https://www.paypal.com/cgi-bin/webscr” for live.

API Integration
================
coming soon……

Magic of Indexing

July 23rd, 2009 by divyang.shah § 7

Today I am going to share something I know about indexing. I am sure you all must be using it somewhere or must have heard of it.

Let’s see one wonderful example of its usage today which will show how important it is to use indexes properly in Database. I would like to thank my client and my mentor Stephen Fegel of Galatea Systems for imparting this wonderful knowledge.

We all use “Select” for retrieving data from the tables. In most cases if data is not too much it takes minimal time to fetch records without indexing also. But in case of large data this may be a severe problem.

Lets take an example:

I have two tables one is houses which is my main table and it has 25,666 records.

And another table is house_desc which has 6,04,255 records.

And the query is

SELECT
SQL_NO_CACHE h.*,
(SELECT
SQL_NO_CACHE desc_value
FROM
house_desc AS d
WHERE
language_id = ‘EN’
AND
d.house_id = h.house_id
AND
(
desc_type = ‘description’
OR
desc_type = ‘introduction’
)
ORDER BY desc_type
LIMIT 0 , 1
)
AS
desc_value
FROM
houses AS h
WHERE
house_id
IN (’12345678′)

Now lets join both the tables and fire sub query for retrieving data from house_desc table.

Structure of the house_desc is

`c_code` varchar(50)
`house_id` int(10)
`country` char(2)
`language_id` enum(‘NL’,'EN’,'DE’,'FR’,'ES’,'IT’)
`desc_type` varchar(50)
`desc_value` longtext

So when I fire the query without indexing and I get following result

Showing rows 0 – 0 (1 total, Query took 13.0067 sec)

It returns only 1 row but still it took 13 secs!!

Now just see the magic of indexing here. Just set the index on house_id field
Fire the same query again and here is the result:

Showing rows 0 – 0 (1 total, Query took 0.0899 sec)

Output is same but just look at the difference in time to fetch records!

Before indexing it took 13.0067 seconds and after indexing it took 0.0899 seconds i.e. it is 1000 time faster than without indexing.

The result may be different in your case as in sometimes it can be 100 time faster or 10 time faster but one thing is for sure that it will be faster than without indexing (if done correctly!).

When you have large amount of records in your table and you want to search that table then it is better to set index on those fields which are there in where clause.

You can’t set index on all the fields from table. It is also very important thing on which filed you set the index.

You can read more on indexing from this
http://www.informit.com/articles/article.aspx?p=377652

Create ZIP file archives on the fly-PHP

May 29th, 2009 by vidyadhar.yagnik § 6

In some website there is need of downloading functionality of multiple files. In that case it is headache for PHP developer that how to give option for download multiple file in single click with lower bandwidth. So, the solution is here: just create zip file containing all the files and give one link for download the zip files.

createZip.inc.php is a class which creates zip file from different files stored on various directories on server and output the necessary request response headers to serve the generated ZIP archive for download.

Example Code Snippet:

include_once("createZip.inc.php");
$createZip = new createZip;
$directoryName = "DownloadImages/";

$createZip -> addDirectory($directoryName); // Adding Directory to ZIP file

$file1ToZip = “image1.jpeg”; // filename1 which is to be added in zip
$fileContents=file_get_contents($file1ToZip);
$createZipFile->addFile($fileContents, $directoryName.$file1ToZip);

$file2ToZip = “image2.jpeg”; // filename2 which is to be added in zip
$fileContents=file_get_contents($file2ToZip);
$createZipFile->addFile($fileContents, $directoryName.$fileToZip);

$outputDir = “./”;
$outputFile = $outputDir.”Images.zip”; // Zip file name

$fd = fopen ($outputFile, “wb”); // Temporary Creating file on disk
$out = fwrite ($fd, $createZip -> getZippedfile()); // Writing zip contents to temporary file
fclose ($fd);

$createZip -> forceDownload($outputFile); // stream the generated ZIP archive for download

@unlink($outputFile); // unlink temporary file

Credits goes to Author of the class: “Rochak Chauhan”
Source: http://www.phpclasses.org/browse/package/2322.html

Author:
Vidyadhar Yagnik
PHP Developer: Digicorp Information Systems Pvt. Ltd.
[email protected]

Things to take care while developing Arabic Sites and Applications

May 26th, 2009 by devdatt.mehta § 0

We are working with clients in Middle East for almost 5 years now and we have learned lot of things about development in Arabic language.

Following are some points which will help you in developing any website or application in Arabic.

  • Arabic is written right to left
  • If you are developing it for Kuwait clients price should be in KD and with 3 Decimal pleases.
  • How to display Arabic word in html ? Should I use UTF-8 charset to display Arabic in html page ?

For example =>

HTML HEAD TAG definition.

<html xmlns=http://www.w3.org/1999/xhtml>

<head>

<meta http-equiv=’content-type’ content=’text/html; charset=UTF-8′>

<title>الاختبار</title>

</head>

<body dir=’rtl’>

الاختبار

</body>

</html>

  • How to convert direction in html for Arabic ?

Arabic script is written from right to left direction of the page so to Display Arabic content use dir=’rtl’ attribute in html tag or direction=’rtl’   for css/inline style sheet. It is always right aligned.

For example

<html xmlns=http://www.w3.org/1999/xhtml>

<head>

<meta http-equiv=’content-type’ content=’text/html; charset=UTF-8′>

<title>الاختبار</title>

<body dir=’rtl’>

<div style=’direction:rtl;‘>

الاختبار

</div>

<table dir=”rtl”>

<tr>

<td align=’right’>الاختبار</td>

</tr>

</table>

</body>

</html>

  • Which format of Arabic words are displayed properly and in readable format ?

Use Font to display Arabic words in “Tahoma: font size 12”.

For example

<html xmlns=http://www.w3.org/1999/xhtml>

<head>

<meta http-equiv=’content-type’ content=’text/html; charset=UTF-8′>

<title>الاختبار</title>

<body dir=”rtl” style=”font-size:12px;font-family:Tahoma,Arial;”>

<div style=”direction:rtl;text-align:right;”>الاختبار</div>

</body>

</html>

  • How to save Arabic data in MySQL or database ?

Use following step to insert, save and retrieve Arabic data.

Step – 1 Table collection should be in “utf8_unicode_ci”

Step – 2 Field collection should be in “utf8_unicode_ci”

Step – 3 Use following code after connection with database. it will

set MySQL server in “utf8 character set”.

mysql_query(“SET NAMES ‘utf8′”);

For Ref:http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html

  • How to search Arabic word in php scripts?

    or

    How to develop Arabic search functionality in php scripts ?

If you are not storing data in UTF-8 then you must use “urlencode” and   “urldecode” function

For example

At the time of request.

$keyword = urldecode($_POST['keyword']);

SELECT * FROM <table_name> WHERE <Field Name> LIKE ‘%$keyword%’

At the time of redirect.

$keyword = urlencode($keyword);

header(‘location: file.php?keyword=$keyword’);

or

<script type=’text/javascript’>

window.location.href = “file.php?keyword=<?=$keyword?>”;

</script>

  • Suggestion for multi language application setup

For example English and Arabic

1.  Use prefix/LANG_CODE “ar_” and “en_” concat with field name.</

 

2.  Query format

SELECT LANG_CODE.”field1″, LANG_CODE.”field2″,….

3 Multi language application folder structure. It is better that you should store css and images in different folder.

For example

Folder Structure

-CSS_EN

-CSS_AR

-IMAGES_EN

-IMAGES_AR

4. Words module

- Give rights to administrator to edit Arabic and English word to rectify any mistake, if any.

- For retrieve data rapidly must store all Arabic and English word in .xml file.

For example

<?xml version=’1.0′ encoding=’UTF-8′?>

<lang>

<words>

<word id=”1″ english=”Sign In” arabic=”تسجيل“></word>

</words>

</lang>

Create PHP constant file for words.

ar_words.php

<?php

define(SIGNIN,trim(str_replace(‘#’,'&#’,$p->output['0']['child'][0]['child'][3]['attrs']['ARABIC'])),” “);

?>

en_words.php

<?php

define(SIGNIN,$p->output['0']['child'][0]['child'][3]['attrs']['ENGLISH']);

?>

Let us know if you feel some important points are missing here.

 

 

How to Install and Configure MySql, Apache2, PHP, ffmpeg on Fedora Linux

May 26th, 2009 by bhumish.shah § 3

Following Are The Steps for MySql Server Installation

1. To download MySql Source Go To Below link

Note: There Are 2 Versions Available For MySql

1) Community Edition: (It’s a Free Edition)

2) Enterprise Edition: (You Have To Purchase License For MySql)

http://dev.mysql.com/downloads/

2. In This Example We Are Going To Install Mysql-communitiry Edition

Rpm Package for MySql MySQL-server-community-5.1.34-0.rhel5.i386.rpm

Note: For Example if you are Using Fedora, Redhat, CentOS, Then You Have to Download RPM Package .

If You Are Using Debian, Ubuntu Then You have to download deb Package

3. For Mysql-Server Installation Type the Following Command on Terminal

rpm -ivh MySQL-server-community-5.1.34-0.rhel5.i386.rpm

You Can Also Install MySql Server on Server Using the Following command

yum install mysql-server

To start Mysql Automatically After System Reboot

chkconfig mysqld on

To Check Whether mysql Server is Installed or Not

rpm -q mysql

This command Give the Output of Mysql Installed Version on Server

To Restart, Stop, Start Mysql Use the Following Command

/etc/init.d/mysqld restart

/etc/init.d/mysqld stop

/etc/init.d/mysqld start

4. For MySql Administration you have to install Mysql-administrator And MySql-Query-Browser

To Do This

Yum install mysql-Query-browser

Yum install mysql-administrator


How to Install Apache2 on Linux Server ?

1. Apache2 Is Installed by Default in Many Version of Linux If You Select WebServer Option during Your Linux Server Installation

2. You Can Also Manually Install Apache2 using Following RPMS on your Linux distribution CD

rpm -ivh httpd

rpm -ivh httpd-devel

3. To Install Apache2 with Yum Type The Following Command

Yum install httpd

To check whether apache2 is installed or not

rpm -q httpd

To Start Apache2 When System boots

Chkconfig httpd on

To Restart , Stop , Start apache2 Use The Following command

/etc/init.d/httpd restart

/etc/init.d/httpd stop

/etc/init.d/httpd start

Note: /var/www/html/ is Root Folder for Apache2. You have To Put Your Application In /var/root/html/ Folder To Run Your Site


How to Install PHP on Linux Server ?

PHP Is Installed By Default In Many Linux Edition. To Install PHP Type The Following Command

1. Yum install php

Note : php.ini File Is Located On /etc/ Folder .


How to Install FFMPEG on Linux Server ?

1. Install PHP, necessary extensions and supporting software.

Open Terminal & Type the Following Command

2. Yum -y install php-devel php-gd php-mbstring gcc gcc-c++ libtool svn git yasm gsm-devel libogg-devel libvorbis-devel libtheora-devel;

3. wget http://downloads.sourceforge.net/ffmpeg-php/ffmpeg-php-0.5.3.1.tbz2; \

4. tar -jxvf ffmpeg-php-0.5.3.1.tbz2; \

5. cd ffmpeg-php-0.5.3.1; \

6. phpize; \

7  ./configure –prefix=/usr; \

8. make; \

9. make install; \

10. cd ..;

11. add ffmpeg.so extension to php.ini file

Extension=ffmpeg.so

12. Restart httpd Service

/etc/init.d/httpd restart

13. To Verify ffmpeg Installation run phpinfo file on server & Find ffmpeg Entry

14. To download ffmpeg php Extension Go to Below Link

http://sourceforge.net/projects/ffmpeg-php/

open above link and click in Download ffmpeg-php -0.6.0

Prevention of Sql Injection with PHP

May 22nd, 2009 by divyang.shah § 15

Preventing SQL injection attack is becoming a headache now a days for many application developers and especially for web application developers. Lets explore a scenario where SQL Injection attack is most common and how we can avoid that.

We generally have a login screen with username and password in almost every web application.

Assume that attacker passes values like following:

user name = a’ or ‘t’='t
pass =  a’ or ‘t’='t

Generally we have query like following:
“select * from admin where name = ‘”.$_POST['user_name'].”‘ and psw = ‘”.$_POST['pass'].”‘”;

So after passing the value it will look like:
select * from admin where name = ‘a’ OR ‘t’='t’ and psw = ‘a’ OR ‘t’='t’;

If you see properly this will go true and return the first record of the database and set that into session for login and user will be in your system!! It’s so easy, isn’t  it?

To avoid this embarrassing situation there are many ways:

1) You can set ON magic quotes of your server. It is same as addslashes() function. It will be there in your php.ini file.

(NOTE : This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.)

2) You can manually addslashes like following

$user_name = addslashes($_POST['user_name']);
$pass = addslashes($_POST['pass']);

and then pass these parameters into query like this
“select * from admin where name = ‘”.$user_name.”‘ and psw = ‘”.$pass.”‘”;

so now it will look something like this
select * from admin where name = ‘a’ OR ‘t’='t’ and psw = ‘a’ OR ‘t’='t’;

so now it will match whole word (a’ OR ‘t’='t) with database and will return empty result set.

3) If you want to do it in one query then use mysql_real_escape_string.
“select * from tbladmin where name = ‘”.mysql_escape_string($_POST['username']).”‘ and psw = ‘”.mysql_escape_string($_POST['pass']).”‘”;

mysql_escape_string is more appropriate then addslashes().

you can read that thing here

http://shiflett.org/blog/2006/jan/addslashes-versus-mysql-re…

This will also provide the same result as point 2.

4) Another and best solution is Prepared Statements.

Prepared statements can help increase security by separating SQL logic from the data being supplied. This separation of logic and data can help prevent SQL injection attack.

mysql> PREPARE stmt_name FROM "SELECT name FROM Country WHERE code = ?";
//Statement prepared

mysql> SET @test_parm = "FIN";
// set the parameter

mysql> EXECUTE stmt_name USING @test_parm;
+---------+
| Name    |
+---------+
| Finland |
+---------+

mysql> DEALLOCATE PREPARE stmt_name;

Read more about prepared statement from this
http://dev.mysql.com/tech-resources/articles/4.1/prepared-statements.html

5) If you don’t want to use any of the functions then you can break your query in 2 steps like this

“select * from admin where name = ‘”.$_POST['user_name'].”‘”;

So from this you will get first record from the database. Now check $_POST['pass'] with obtain result.

Like you store the query result into $result variable. So in $result[0]['pass'] you will get original password. So now check
if($result[0]['pass'] == $_POST['pass'])

And then do the remaining process.

So by using any of the above steps you can avoid Sql Injection in your login form.

But the best way is to use point 2 and 3 and 4 because if hacker enters a’;drop table users; select * from data where name like ‘%
in user name field then it will look something like this

select * from users where name = ‘a’;drop table users; select * from data where name like ‘%’;

and it will fire 3 queries at same time and it will drop your users table.

1st, 2nd 3rd and 4th points had good results but as you can see the note in 1st point and 3rd point has more advantage then 2nd point. So the 3rd and 4th points are best solution and for more security purpose you can use 3rd or 4th point together.

Like
$format=”select * from users where `user_password` = ‘%s’ and `user_name` = %s
$query=sprintf($format,mysql_real_escape_string($password), mysql_real_escape_string($user_name) );

Good practice is to use use 3rd or 4th point.

Same way you can use this method at any of the user input forms like in user registration or in add product form. Any of the place where you are taking input from user side you have to check the data first and then store that data into database. And same way you can use the htmlentities() function to avoid html code.

Do you know any more methods using which we can prevent it? Let us know.

How to integrate Uber uploader in CakePHP

May 2nd, 2009 by nayan.lodha § 2

Uber-Uploader

Uber-Uploader is a group of programs written in Perl, PHP and Javascript. It is intended to present a graphical representation of the status of a web based file upload in the form of a progress bar.

External Links

CakePHP

CakePHP is a free, open-source, rapid development framework for PHP. It’s a foundational structure for programmers to create web applications. Our primary goal is to enable you to work in a structured and rapid manner–without loss of flexibility.

CakePHP takes the monotony out of web development. We provide you with all the tools you need to get started coding what you really need to get done: the logic specific to your application. Instead of reinventing the wheel every time you sit down to a new project, check out a copy of CakePHP and get started with the real guts of your application.

Why We Need To Integrate CakePHP With Uber-Uploader

As mention above  Uber-Uploader is a group of programs written in Perl, PHP and Javascript.It is used to upload large volume video files.It also provide a very good GUI as progress bar and show some  informaton like Elapsed Time ,Est Time Left ,Percent Complete etc that helps user to keep patience while upload a large volum files.

Here is the some steps How to integrate uber uploader in cakePHP

1.Create a folder in Webroot/files and put all files in that folder
eg. i created ‘uploder’ in webroot/files than i created ‘html’ folder in ‘uploder’ folder

2.Set the $TEMP_DIR value in ‘ubr_upload.pl’ AND ‘ubr_ini.php’.
eg. $TEMP_DIR = ‘/xyz.com/html/tmp/ubr_temp/’;
eg. $TEMP_DIR = ‘/var/tmp/ubr_temp/’;
eg. $TEMP_DIR = ‘/usr/home/roger/ubr_temp/’;

3.Set the $_CONFIG['upload_dir'] value in ‘ubr_default_config.php’. It should be physical path
eg. $_CONFIG['upload_dir'] = ‘/XYZ.com/app/webroot/files/uploader/html/tmp/ubr_uploads’;
eg. $_CONFIG['upload_dir'] = ‘/var/www/html/ubr_uploads/’;
eg. $_CONFIG['upload_dir'] = ‘/usr/local/www/htdocs/ubr_uploads/’;
eg. $_CONFIG['upload_dir'] = $ENV{‘DOCUMENT_ROOT’} . ‘/ubr_uploads/’;

4.Set the correct path values for the scripts in ‘ubr_ini.php’.
eg. PATH_TO_UPLOAD_SCRIPT       = ‘../app/webroot/files/uploader/html/cgi-bin/ubr_upload.pl’;      // Path info
PATH_TO_LINK_SCRIPT         = ‘../app/webroot/files/uploader/html/ubr_link_upload.php’;        // Path info
PATH_TO_SET_PROGRESS_SCRIPT = ‘../app/webroot/files/uploader/html/ubr_set_progress.php’;       // Path info
PATH_TO_GET_PROGRESS_SCRIPT = ‘../app/webroot/files/uploader/html/ubr_get_progress.php’;       // Path info
PATH_TO_JS_SCRIPT           = ‘../app/webroot/files/uploader/html/ubr_file_upload.js’;         // Path info
PATH_TO_JQUERY              = ‘../app/webroot/files/uploader/html/jquery-1.3.1.min.js’;        // Path Info
PATH_TO_CSS_FILE            = ‘../app/webroot/files/uploader/html/ubr.css’;                    // Path info
DEFAULT_CONFIG              = ‘/XYZ.com/app/webroot/files/uploader/html/ubr_default_config.php’;     // Path info

5.Make ubr_pload.pl executable with the command chmod 755 ubr_pload.pl

6.Set the correct path for $_CONFIG['redirect_url']  in ‘ubr_default_config.php’

7.Set the correct path for $_CONFIG['path_to_upload'] and $_CONFIG['upload_dir'] in ‘ubr_default_config.php’.It is the Directory where the video get uplaod
eg. /home/xyz.com/app/webroot/files/uploader/html/tmp/ubr_uploads/

8.Make sure that both path ($_CONFIG['path_to_upload'] and $_CONFIG['upload_dir']) should be same.

9 Make sure that path for $TEMP_DIR in ubr_upload.pl should be same to $TEMP_DIR value in ‘ubr_ini.php

10.Now Create a action in controller and include the following code
eg  action “uploadvideo” in videos_controller

$this->set(“DEBUG_AJAX”,$DEBUG_AJAX);
$this->set(“PATH_TO_UPLOAD_SCRIPT”,$PATH_TO_UPLOAD_SCRIPT);

$this->set(“PATH_TO_JQUERY”,$PATH_TO_JQUERY);
$this->set(“PATH_TO_GET_PROGRESS_SCRIPT”,$PATH_TO_GET_PROGRESS_SCRIPT);
$this->set(“PATH_TO_SET_PROGRESS_SCRIPT”,$PATH_TO_SET_PROGRESS_SCRIPT);
$this->set(“PATH_TO_CSS_FILE”,$PATH_TO_CSS_FILE);
$this->set(“DEFAULT_CONFIG”,$DEFAULT_CONFIG);
$this->set(“MULTI_CONFIGS_ENABLED”,$MULTI_CONFIGS_ENABLED);
$this->set(“PATH_TO_LINK_SCRIPT”,$PATH_TO_LINK_SCRIPT);
$this->set(“PATH_TO_JS_SCRIPT”,$PATH_TO_JS_SCRIPT);
$this->set(“_CONFIG”,$_CONFIG);

$this->set(“CGI_UPLOAD_HOOK”,$CGI_UPLOAD_HOOK);
$this->set(“GET_PROGRESS_SPEED”,$GET_PROGRESS_SPEED);

$this->set(“DELETE_LINK_FILE”,$DELETE_LINK_FILE);
if($PHP_ERROR_REPORTING){ error_reporting(E_ALL); }

header(‘Content-type: text/html; charset=UTF-8′);
header(‘Expires: Mon, 26 Jul 1997 05:00:00 GMT’);
header(‘Last-Modified: ‘ . date(‘r’));
header(‘Cache-Control: no-store, no-cache, must-revalidate’);
header(‘Cache-Control: post-check=0, pre-check=0′, FALSE);
header(‘Pragma: no-cache’);

//Set config file
if($MULTI_CONFIGS_ENABLED){
// Put your multi config file code here
$config_file = ‘ubr_default_config.php’;
}
else{ $config_file = $DEFAULT_CONFIG; }

// Load config file
require $config_file;
//***************************************************************************************************************
// The following possible query string formats are assumed
//
// 1. No query string
// 2. ?about=1
//***************************************************************************************************************
if($DEBUG_PHP){ phpinfo(); exit(); }
elseif($DEBUG_CONFIG){ debug1($_CONFIG['config_file_name'], $_CONFIG); exit(); }
elseif(isset($_GET['about']) && $_GET['about'] == 1){
kak(“<u><b>UBER UPLOADER FILE UPLOAD</b></u><br>UBER UPLOADER VERSION =  <b>” . $UBER_VERSION . “</b><br>UBR_FILE_UPLOAD = <b>” . $THIS_VERSION . “</b><br>\n”, 1, __LINE__);
}

11. Now put the following code in CTP file(“uploadvideo.ctp” )

<style>
.debug {font:16px Arial; background-color:#FFFFFF; border:1px solid #898989; width:700px; height:100px; overflow:auto;}
.alert {font:18px Arial;}
.data {background-color:#b3b3b3; border:1px solid #898989; width:350px;}
.data tr td {background-color:#dddddd; font:13px Arial; width:35%;}
.bar1 {background-color:#b3b3b3; position:relative; text-align:left; height:20px; width:<?php print $_CONFIG['progress_bar_width']; ?>px; border:1px solid #505050;}
.bar2 {background-color:#000099; position:relative; text-align:left; height:20px; width:0%;}
</style>
<script language=”JavaScript” type=”text/JavaScript” src=”../app/webroot/files/uploader/html/jquery-1.3.1.min.js”></script>
<script language=”javascript” type=”text/javascript” src=”../app/webroot/files/uploader/html/ubr_file_upload.js”></script>
<script language=”javascript” type=”text/javascript”>
var upload_range = 1;
var path_to_link_script = “<?php print $PATH_TO_LINK_SCRIPT; ?>”;
var path_to_set_progress_script = “<?php print $PATH_TO_SET_PROGRESS_SCRIPT; ?>”;
var path_to_get_progress_script = “<?php print $PATH_TO_GET_PROGRESS_SCRIPT; ?>”;
var path_to_upload_script = “<?php print $PATH_TO_UPLOAD_SCRIPT; ?>”;
var multi_configs_enabled = <?php print $MULTI_CONFIGS_ENABLED; ?>;
var check_allow_extensions_on_client = <?php print $_CONFIG['check_allow_extensions_on_client']; ?>;
var check_disallow_extensions_on_client = <?php print $_CONFIG['check_disallow_extensions_on_client']; ?>;
<?php if($_CONFIG['check_allow_extensions_on_client']){ print “var allow_extensions = /” . $_CONFIG['allow_extensions'] . “$/i;\n”; } ?>
<?php if($_CONFIG['check_disallow_extensions_on_client']){ print “var disallow_extensions = /” . $_CONFIG['disallow_extensions'] . “$/i;\n”; } ?>
var check_file_name_format = <?php print $_CONFIG['check_file_name_format']; ?>;
<?php if($_CONFIG['check_file_name_format']){ print “var check_file_name_regex = /” . $_CONFIG['check_file_name_regex'] . “/;\n”; } ?>
<?php if($_CONFIG['check_file_name_format']){ print “var check_file_name_error_message = ‘” . $_CONFIG['check_file_name_error_message'] . “‘;\n”; } ?>
<?php if($_CONFIG['check_file_name_format']){ print “var max_file_name_chars = ” . $_CONFIG['max_file_name_chars'] . “;\n”; } ?>
<?php if($_CONFIG['check_file_name_format']){ print “var min_file_name_chars = ” . $_CONFIG['min_file_name_chars'] . “;\n”; } ?>
var check_null_file_count = <?php print $_CONFIG['check_null_file_count']; ?>;
var check_duplicate_file_count = <?php print $_CONFIG['check_duplicate_file_count']; ?>;
var max_upload_slots = <?php print $_CONFIG['max_upload_slots']; ?>;
var cedric_progress_bar = <?php print $_CONFIG['cedric_progress_bar']; ?>;
var cedric_hold_to_sync = <?php print $_CONFIG['cedric_hold_to_sync']; ?>;
var bucket_progress_bar = <?php print $_CONFIG['bucket_progress_bar']; ?>;
var progress_bar_width = <?php print $_CONFIG['progress_bar_width']; ?>;
var show_percent_complete = <?php print $_CONFIG['show_percent_complete']; ?>;
var show_files_uploaded = <?php print $_CONFIG['show_files_uploaded']; ?>;
var show_current_position = <?php print $_CONFIG['show_current_position']; ?>;
var show_current_file = <?php if($CGI_UPLOAD_HOOK && $_CONFIG['show_current_file']){ print “1″; }else{ print “0″; } ?>;
var show_elapsed_time = <?php print $_CONFIG['show_elapsed_time']; ?>;
var show_est_time_left = <?php print $_CONFIG['show_est_time_left']; ?>;
var show_est_speed = <?php print $_CONFIG['show_est_speed']; ?>;
var JQ = jQuery.noConflict();

JQ(document).ready(function(){
iniFilePage();
JQ(“#upfile_0″).bind(“keypress”, function(e){ if(e == 13){ return false; } });
//JQ(“#upfile_0″).bind(“change”, function(e){ addUploadSlot(1); });
JQ(“#upload_button”).bind(“click”, function(e){ //alert(valid.validate());
if(valid.validate())
linkUpload();
});
JQ(“#reset_button”).bind(“click”, function(e){ resetForm(); });
});
</script>

<script type=”text/javascript” src=”http://www.xyz.com/app/webroot/files/uploader/html/ubr_file_upload.js” ></script>
<link href=”http://www.xyz.com/app/webroot/files/uploader/html/ubr.css” type=”text/css” rel=”stylesheet” />

<!– Start Progress Bar –>
<div align=”center” id=”progress_bar” style=”display:none;”>
<div id=”upload_status_wrap” class=”ubrBar1″  style=”width:400px”>
<div id=”upload_status” class=”ubrBar2″></div>
</div>
<?php if($_CONFIG['show_percent_complete'] || $_CONFIG['show_files_uploaded'] || $_CONFIG['show_current_position'] || $_CONFIG['show_elapsed_time'] || $_CONFIG['show_est_time_left'] || $_CONFIG['show_est_speed']){ ?>
<br>
<table class=”ubrUploadData”>
<?php if($_CONFIG['show_percent_complete']){ ?>
<tr>
<td class=’ubrUploadDataLabel’>Percent Complete:</td>
<td class=’ubrUploadDataInfo’><span id=”percent_complete”>0%</span></td>
</tr>
<?php } ?>
<?php if($_CONFIG['show_files_uploaded']){ ?>
<tr>
<td class=’ubrUploadDataLabel’>Files Uploaded:</td>
<td class=’ubrUploadDataInfo’><span id=”files_uploaded”>0</span> of <span id=”total_uploads”></span></td>
</tr>
<?php } ?>
<?php if($_CONFIG['show_current_position']){ ?>
<tr>
<td class=’ubrUploadDataLabel’>Current Position:</td>
<td class=’ubrUploadDataInfo’><span id=”current_position”>0</span> / <span id=”total_kbytes”></span> KBytes</td>
</tr>
<?php } ?>
<?php if($CGI_UPLOAD_HOOK && $_CONFIG['show_current_file']){ ?>
<tr>
<td class=’ubrUploadDataLabel’>Current File Uploading:</td>
<td class=’ubrUploadDataInfo’><span id=”current_file”></span></td>
</tr>
<?php } ?>
<?php if($_CONFIG['show_elapsed_time']){ ?>
<tr>
<td class=’ubrUploadDataLabel’>Elapsed Time:</td>
<td class=’ubrUploadDataInfo’><span id=”elapsed_time”>0</span></td>
</tr>
<?php } ?>
<?php if($_CONFIG['show_est_time_left']){ ?>
<tr>
<td class=’ubrUploadDataLabel’>Est Time Left:</td>
<td class=’ubrUploadDataInfo’><span id=”est_time_left”>0</span></td>
</tr>
<?php } ?>
<?php if($_CONFIG['show_est_speed']){ ?>
<tr>
<td class=’ubrUploadDataLabel’>Est Speed:</td>
<td class=’ubrUploadDataInfo’><span id=”est_speed”>0</span> KB/s.</td>
</tr>
<?php } ?>
</table>
<?php } ?>
</div>
<!– End Progress Bar –>

<!– Start Upload Form –>
<form name=”form_upload” id=”form_upload” <?php if($_CONFIG['embedded_upload_results'] || $_CONFIG['opera_browser'] || $_CONFIG['safari_browser']){ print “target=\”upload_iframe\”"; } ?> method=”post” enctype=”multipart/form-data”  action=”#” style=”margin: 0px; padding: 0px;”>
<noscript><font color=’red’>Warning: </font>Javascript must be enabled to use this uploader.<br><br></noscript>
<!– Include extra values you want passed to the upload script here. –>
<!– eg. <input type=”text” name=”employee_num” value=”5″> –>
<!– Access the value in the CGI with $query->param(‘employee_num’); –>
<!– Access the value in the PHP finished page with $_POST_DATA['employee_num']; –>
<!– DO NOT USE “upfile_” for any of your values. –>
<div id=”upload_slots”><input type=”file” name=”upfile_0″ size=”90″ <?php if($_CONFIG['multi_upload_slots']){ ?>onChange=”addUploadSlot(1)”<?php } ?>  onkeypress=”return handleKey(event)” value=”"></div>
<br>
<input type=”button” id=”reset_button” name=”reset_button” value=”Reset” onClick=”resetForm();”>&nbsp;&nbsp;&nbsp;<input type=”button” id=”upload_button” name=”upload_button” value=”Upload” onClick=”linkUpload();”>
</form>
<!– End Upload Form –>
</div>
<div id=’ajax_div’><!– Used to store AJAX –></div>

12 Now you can run the code www.xyz.com/videos/uploadvideo

I hope this helps people looking for solution integrating Uber Uploader in Cake PHP. Leave comment in case of any issues.

Working with Arabic Language

April 21st, 2009 by vishal.parmar § 1

We have lot of clients in Middle East and thus we have to develop almost all the projects in English and Arabic.

Developing in Arabic can be quite challanging sometimes not just because it is a different language but it is also read and written from right to left. So it is a very vast subject but right now let us focus on few things.

Following are couple of issues you may come across working with Arabic but there are also simple solutions to them as explained below.

(1) Sending email in Arabic

Sometimes we find that Arabic mail is displayed properly in gmail,yahoo etc but they dont look ok in Outlook, Zimbra.

Instead of Arabic junk data like following comes in email:

áã íÊã ÝÊÍ ãáÝ ÇáÞÇáÈáã íÊã ÝÊÍ ãáÝ ÇáÞÇáÈ
áã íÊã ÝÊÍ ãáÝ ÇáÞÇáÈáã íÊã ÝÊÍ ãáÝ ÇáÞÇáÈ

Solution to this problem is very simple

You just need to set mail header charset as UTF-8 intead of iso-8859-1.

PHP example:

$headers  = ‘MIME-Version: 1.0′ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=UTF-8‘ . “\r\n”;

(2) To display HTML page in Arabic Language

<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=UTF-8“>

I hope this may help you someday when you are stuck.

Would you like to share some of your tips about working with Arabic language here? please write them in comments.

Thanks.

Where Am I?

You are currently browsing the php category at Digicorp.