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");

Thumbnail Drag then Crop like facebook using mootools

I like facebook profile code, when you upload picture you can drag and drop it inside a small box, to get a thumbnail showing the good part of the picture.

facebook_thumbnail

It’s very easy to do it using mootools core and mootools Drag plugin

Click here to see demo
Read the rest of this entry »

PHP cli progress Bar

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

Read the rest of this entry »

Page 3 of 3«123