Automaticly Copy Zend/Symfony Library to Project

Zend Framework Batch file

@echo off
:MENU
ECHO Zend will be copied to "%CD%\library"
SET /P M=Type PRESS 1 to continue or any key to EXIT:
IF %M%==1 (	GOTO IMPORT ) ELSE ( GOTO :EOF )
:IMPORT
xcopy /E "ABSOLUTE_PATH_TO_Zend_Library" "%CD%\library"
GOTO :EOF

Symfony Framework Batch file

@echo off
:MENU
ECHO Symfony will be copied to "%CD%\lib\vendor"
SET /P M=Type PRESS 1 to continue or any key to EXIT:
IF %M%==1 (	GOTO IMPORT ) ELSE ( GOTO :EOF )
:IMPORT
xcopy /E "ABSOLUTE_PATH_TO_Symfony_Library" "%CD%\lib\vendor\"
GOTO :EOF

Read the rest of this entry »

Plesk : How to pointing domain to a subdirectory

First create your “subdirectory_name” then run terminal and edit httpd.include (vi, pico …):

pico /var/www/vhosts/domain.com/conf/httpd.include

Change every “/var/www/vhosts/domain.com/httpdocs
To “/var/www/vhosts/domain.com/httpdocs/subdirectory_name

Restart apache :

service httpd restart

This trick can be used to configure another domain to be pointing in another domaine : exemple

Change every “/var/www/vhosts/domain2.com/httpdocs
To “/var/www/vhosts/domain1.com/httpdocs

Marquee using mootools

I think that everyone has a love story with marquee, I remember my first html page in notepad with a lot of <Marquee>.

Today too, this tag still has the same charm, I love it.
I’ve made a little class using mootools to reborn my favorite html tag.

  • Easy to setup.
  • Stop “onmouseover”
  • Restart “onmouseout”

See demo

For this moment, this class support only “slide” from right to left, I’ll add direction option when I’ve finished some works.

Download script

UTF-8 and live.com (hotmail) issue

It is necessary to know first of all that: the problems with e-mails sent with UTF8 encoding  is not your, but that of the system of the addressee which does not manage correctly 8 bits,  as case of “Mail Subject” in “LIVE.com” (hotmail).

The solution is encoding the data of the message in MIME base64 :

Example :

mail($emailto,"=?UTF-8?B?".base64_encode($subject)."?=",$message,$headers);

CSS : “float” property vs “Display:inline-block”

I confess that I’ve never worked with the CSS attribute “display: inline-block“, I thank Firebug and error in the Live.com site for this discovery.

This property allows to apply two kinds of “display” for the same element, in addition there is an equivalent for FireFox as well, namely “display:-moz-inline-box“.

Example :

#content div.left{
	width:180px;
	display:-moz-inline-box;
	display:inline-block;
}
/* Hack for IE */
* html #content div.left{
	display:inline;
}

Another advantages :
Consideration of the property “vertical-align“.
Ability to leave free the height of the element, unlike “float”.

See layout demo

See “float:left” vs “display:block-inline” fight

Are you ready to kill FLOAT ??

SQL_CALC_FOUND_ROWS vs mysql_num_rows()

What function do you use to return the number of records in a MYSQL table and why?
To understand the difference between SQL_CALC_FOUND_ROWS and mysql_num_rows()

sql_calc_found_rows

$sql  = mysql_query("
                              SELECT      SQL_CALC_FOUND_ROWS id
                              FROM        table
                              WHERE       id_msg  =  2
                            ");
$pages_resultats	=	mysql_query("SELECT FOUND_ROWS()");
list($nbr_resultats) = mysql_fetch_array($pages_resultats);

Resultats :

echo mysql_num_rows($sql); // Return 4
echo $nbr_resultats; // Return 4

Now add “Limit” to query and retry :

$sql  = mysql_query("
                              SELECT      SQL_CALC_FOUND_ROWS id
                              FROM        table
                              WHERE       id_msg  =  2
                              LIMIT       2
                            ");
$pages_resultats	=	mysql_query("SELECT FOUND_ROWS()");
list($nbr_resultats) = mysql_fetch_array($pages_resultats);

Resultats :

echo mysql_num_rows($sql); // Return 2
echo $nbr_resultats; // Return always 4

Unlike mysql_num_rows() or COUNT(), the function SQL_CALC_FOUND_ROWS is not affected by the LIMIT clause.
SQL_CALC_FOUND_ROWS is ideal for paging navigation.

Check if “is digits” and does not begin with zero

Protecting Your PHP/SQL Queries from SQL Injection is one of coding obligations, if you have tables with AUTO_INCREMENT and you want to check IDs before running queries, this function is yours.

function is_digits($string){
	return preg_match("!^[1-9]([0-9]+)?$!",$string);
}

Examples :

is_digits(0); // Return 0
is_digits(1); // Return 1
is_digits("1"); // Return 1
is_digits(01); // Return 0
is_digits(-1); // Return 0
is_digits("1a"); // Return 0
is_digits("a1"); // Return 0
is_digits(15); // Return 1
is_digits(1,5); // Return 0
is_digits(1.5); // Return 0

Mysql FIND_IN_SET()

FIND_IN_SET() : A function that I discovered some years ago and which I find very impressive if you’re addicted to query optimization.
This function is a bit like in_array() but is doing research in StringList separated by commas “,”

Here is an example to understand:

Table : Clubs
table_clubs

Table : Leagues
championnats

To select leagues which participates BARCA (having id 11), SQL code would look like this :

SELECT    league_id,name
FROM      Leagues
WHERE     FIND_IN_SET(11, clubs_id)

Create a new directory having 0777 permissions

I need to create unique directory for every new member, which will be used to store their pictures. I’ve tried :

mkdir("user_name", 0777);

I got : mkdir() [function.mkdir]: Permission denied

It work when I chmod parent directory but can not give permissions “0777”, therefore I add umask()

umask(000);
mkdir("user_name", 0777);

Eurêka BUT ! the new folder is now owned by mr apache

Owned by apache

Now imagine that we want to create a subfolder like “user_name/gallery” ! we will get an error like :

Warning: mkdir() [function.mkdir]: SAFE MODE Restriction in effect. The script whose uid is XXX is not allowed to access /var/www/vhosts/updel.com/httpdocs/test/test owned by uid 48 in /var/www/vhosts/updel.com/httpdocs/test.php on line 4

It mean we do not have permission to touch a directory owned by another user !!!!!!!!

The solution : FORGET mkdir() and through ftp using PHP, the code look like this

$connexion_ftp = ftp_connect("Ftp_url"); //Connexion ftp
ftp_login($connexion_ftp, "Ftp_login", "Ftp_Password");
ftp_mkdir($connexion_ftp, "new_dir"); // user_name in my case
ftp_site($connexion_ftp,"CHMOD 777 new_dir");

PHP cli progress Bar

This is a simple trick to make your PHP console application more funny

Read the rest of this entry »