Unzip Folder Using PHP

Filed Under (PHP) by convertallfile on 07-11-2012


//Photo is the folder that sss.zip file presents..

// Enable ZIP in php info
$source1=’sss.zip’;

$zip = new ZipArchive;

$res = $zip->open(‘photo/’.$source1);
if ($res === TRUE)
{
$zip->extractTo(“photo/”);
$zip->close();
$err.=”1. The $source1 unzipped successfully.<br><br>”;
}
else
{
$err.=”1. The $source1 not able to Extract.<br><br>”;
}

Set write permission for Folders and its Files in linux

Filed Under (Linux) by convertallfile on 09-02-2012

Login via terminal with root user, Then

chmod 777 -R Folder_name/

Install LAMP on centos

Filed Under (Linux) by convertallfile on 09-02-2012

First Install Apache

1. yum install httpd httpd-devel
2. /etc/init.d/httpd start

 

Second Install MySQL

1. yum install mysql mysql-server mysql-devel
2. mysql

If you attempt to type mysql in command prompt, you will be getting this error.

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

This is because you are not running the mysqld daemon before launching the mysql client. The file /var/lib/mysql/mysql.sock will be automatically created upon running the first instance of mysql.

To fix:

First start the mysql daemon, then type mysql:

1. /etc/init.d/mysqld start
2. mysql

 

Changing MySQL Root Password

By default the root password is empty for the mysql database. It is a good idea to change the mysql root password to a new one from a security point of view.

mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD(‘newpassword’) WHERE user=’root’;
mysql> FLUSH PRIVILEGES;

Once done, check by logging in:

mysql -u root -p
Enter Password: <your new password>

 

To Create A New MySQL User

To create a new mysql user ‘guest’ with ‘all privileges’ on the database ‘demo’:

mysql > create database demo
mysql >GRANT ALL PRIVILEGES ON demo.* TO ‘guest’@'localhost’ IDENTIFIED BY ‘guest’ WITH GRANT OPTION;
mysql> UPDATE user SET Password=PASSWORD(‘guest’) WHERE user=’guest’;

That’s it! MySQL is ready! Don’t forget to remember the root password as we might be using it with phpmyadmin.

 

Third Install PHP5 Scripting Language

Installing PHP5 with the necessary modules is so easy and can be configured for both the Apache and mysql environment.

1. yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml

Don’t forget to install php-gd (gd library). It is very important if we plan to run captcha scripts on our server and so as other which are dependent on mysql and other functions.

Restart Apache to load php.

1. /etc/init.d/httpd restart

To Test If PHP Is Working Or Not:

Create a file named /var/www/html/test.php with the following phpinfo() function inside php quotes.

// info.php
  <?php
  phpinfo();
  ?>

Install Wine on centos

Filed Under (Linux) by convertallfile on 09-02-2012

To Install wine on centos, Login via terminal as root user. Then follow the below steps.

a) Download rpmforge rpm.

1. root@server [~]# cd /usr/local/src/

2. root@server [/usr/local/src]# wget http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

b) Install the rpmforge rpm.

1. root@server [/usr/local/src]# rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm

c)  Install wine.

1. root@server [/usr/local/src]#yum install wine -y enablerepo=rpmforge

d) Launch Wine from the Centos Applications menu.

How to hide errors in PHP

Filed Under (PHP) by convertallfile on 28-09-2011

Code :

error_reporting(0);
ini_set(‘display_errors’, ’0′);

Paste the above mentioned code at top of your page, then it hides all errors in your php script.

How to display errors in PHP

Filed Under (PHP) by convertallfile on 28-09-2011

Code :
error_reporting(E_ALL);
ini_set('display_errors', 'On');// set to On or 1

Paste the code in top of the page, then it shows all errors, you affect with.

File writing script in PHP

Filed Under (PHP) by convertallfile on 28-09-2011

Code :

$stringData=’This is convertallfile.com. This convertallfile.com contains convert audio, convert video, convert image, convert currency, Measuring conversions with EMI Calculator.’;
$myFile = “xml_files/convertallfile.txt”; // Provide filename if already exists, else filename automatically creates.
$fh = fopen($myFile, ‘w’) or die(“can’t open file”);
fwrite($fh, $stringData);  // String content to write in the file named convertallfile.txt.
fclose($fh);

Find and replace in PHP

Filed Under (PHP) by convertallfile on 28-09-2011

Code :

$input=’This is convertallfile.com. This convertallfile.com deals about audio, video, image, currency, Measuring conversions with EMI Calculator. ‘;

$output=str_replace(‘convertallfile’, ‘blog.convertallfile’,$input);

It results,

This is blog.convertallfile.com. This blog.convertallfile.com deals about audio, video, image, currency, Measuring conversions with EMI Calculator.

Find and Replace for string using regex in javascript

Filed Under (Javascript) by convertallfile on 28-09-2011

code :

var pattern1=/<\/?ht:[^><]+?>/g;
myregexp = new RegExp(pattern1);
xml_str=xml_str.replace(myregexp, “”);
return xml_str;

The above pattern is, to remove the occurrences that starts with <ht: and </:ht .

Example :

<ht:sitename> <p>This portal named as convertallfile.com</p></ht:sitename>

<ht:useful> <p>This portal named as convertallfile.com</p></ht:useful>

 

Outputs,

<p>This portal named as convertallfile.com</p>

<p>This portal named as convertallfile.com</p>

 

 

Parsing XML and XSL Using PHP Script

Filed Under (PHP) by convertallfile on 28-09-2011

$xml_file=’sample.xml’;
$xsl_file=’sample.xsl’;

$xml->load($xml_file);// Loading XML file
$xsl = new DOMDocument;
$xsl->load($xsl_file);//Loading XSL Filename
$proc = new XSLTProcessor();
$proc->importStyleSheet($xsl);
echo $proc->transformToXML($xml);

 

Install xsl and DOM in your server machine.
It throws error while the parsing is not well formed, else result came..