Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

How Create a Zip File Using PHP

Posted by Unknown On Sunday, 17 November 2013 0 comments


     Hello friends now we are going to discus a small code for creating Zip file using PHP. Creating zip file is simple as comparing with author languages.

PHP have a very useful class called ZipArchive ,To create multiple zip files in this post i will show you how create a ZIP file 





https://app.box.com/s/2zg0c554wceby2bsa2gk



Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

<?phpfunction zipFilesDownload($file_names, $archive_file_name, $file_path)
{
    
$zip = new ZipArchive();
  
    if (
$zip->open($archive_file_name, ZIPARCHIVE::CREATE) !== TRUE) {
        exit(
"cannot open <$archive_file_name>\n");
    }
  
    foreach (
$file_names as $files) {
        
$zip->addFile($file_path . $files, $files);
    }
    
$zip->close();
  
    
header("Content-type: application/zip");
    
header("Content-Disposition: attachment; filename=$archive_file_name");
    
header("Pragma: no-cache");
    
header("Expires: 0");
    
readfile("$archive_file_name");
    exit;
}
$fileNames     = array('files/file1.docx',
    
'files/file1.pdf');$zip_file_name = 'myFile.zip';

$file_path     = dirname(__FILE__) . '/';
zipFilesDownload($fileNames, $zip_file_name, $file_path);
?>

 


READ MORE

zend framework for beginners Part 1

Posted by Unknown On Tuesday, 5 March 2013 0 comments


Hello friends now we are going to discuss on Zend framework, it also known as zf. This is a A to Z step by step articles on zend .this is first one so here cover on the following three basics.
  1. 1.       What is a frame work and why they need?
  2. 2.       Installing zend framework.
  3. 3.       First zend program.



What is a frame work and why they need?

Zend Framework (ZF) is a framework for PHP 5 and it is based on object-oriented paradigm. It is an open-source framework under the BSD License.  The idea of  ZF was conceptualized in the early 2005, and it was publicly announced in October 2005 at the first Zend Conference.
Like other PHP stack zend provides a PHP stack called zend server and also zend provides a IDE for ZF.

Requirements:
To run Zend 1.7.0 we need PHP 5.2.4 or latter .ZF‘s programmer’s reference says strictly 5.2.3 due to some security reasons, for unit testing it need PHP Unit 3.0 or latter
Zend framework of PHP is basically works on MVC architecture   MVC stands for Model View and Controller.
·         Model : The model part deals with the part which is concerned with the specification of the data to be displayed  Business logic part of the program is handled by this part which involves activities like load and save to databases

·         View: Responsibility of this part is to display the content of the application to the user. Usually this section contains the HTML part

·         Controller: This part combines together the specifics of model and view section and gives the assurance of displaying correct data

Installing zend framework. (with xampp )

Now we are going to install ZF framework on our local computer, initially we need to download the zend frame work from http://framework.zend.com/download. Unzip the folder into host c:\xampp\htdocs Since most of the works in ZF is done from command prompt, so we need to do some preliminary settings, so right click on the My Computer icon, select properties, select Advanced tab, click on Environment Variables, now under the System Variables select Path and click edit button, now select the c:\ xampp\htdocs \ZendFramework\bin folder




Now you want to go command prompt (WIN key + R=Run, Window=> type cmd and press enter key). Type zf show version and press enter, it should display like this.



If it works your path variables are working perfect. After that we need create a directory stretcher that helps to reduce our work load and improve readability.Now type the following command which will create the directory structure automatically

.Here we are using XAMPP so we used root folder as htdocs. After executing above comments directory structure will like blow figure.
Now type http://localhost/myfirstproject/public/ in the address bar of the browser and press return key, the output in the browser should be like this:
go to C:\xampp\htdocs\myfirstproject\application\views\scripts\index folder and in the index.phtml and change the existing code with the following:


<?php
echo "<center><b>Hello World</b></center>";
?>





save it and reload page output will as follows
In the next applications we will learn a how connect DB using Zend. plz read some other articles and give some reviews about my personal programming blog.



READ MORE

Password Hashes in PHP

Posted by Unknown On Sunday, 20 January 2013 2 comments

Password Hashes in PHP

Hello friends now we are discussing about some simple security tricks in php, mainly on handling passwords using php. This section explains why password hashing and how can we use hashing.




Why

Every god programmer’s know storing password in form of clear text is bad method of programing .this make user and programmer at risk. This is the main reason why password hashing is used .password hashing are working on the basics of cryptography.
“In cryptography, a cryptographic hash function is a transformation that takes an input and   returns a fixed-size string, which is called the hash value.”
                                                                                                                                                Wikipedia
By applying hashing algorithm’s they make user’s password’s strong.it make difficult to Attackers. PHP offers so simple inbuilt methods to create hashes, such as md5 (), sh1 (), ssha () etc.


                  

How hashing in PHP

  
There are different algorithm’s for creating a hash of a test most popular are md5() and sha()now we disusing about those two first.
                       
             <?php
                $str = "Hello";
                echo md5($str);
             ?>
 The output of the code above will be:

                    8b1a9953c4611296a827abf8c47804d7 

             <?php
                $str = 'Hello';
                 echo sha1($str);
              ?> 
 The output of the code above will be:

                  f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0

In the above example md5 can create a 128 bit of hash from given text, and second one is sha1. It can make 160 bit hash from given password text. But md5 and sha algorithms can decrypt easly with help of rainbow tables.so we need to use next level algorithms.


   
READ MORE

Unzip Zip file with PHP

Posted by Unknown On Sunday, 13 January 2013 0 comments

Unzip Zip file with PHP

       Yesterday I got a question from my friend, how unzip a word file that zipped using PHP. He wants extracting that file on server.Here using php default ZipArchive class.


To start with we should have the following minimum requirements
  • PHP with ziparchive class 

working

  1.     Install this code and edit zipfile name with your file name, and place file with same folder.
  2.     After execution there created a directory extracted and out put file will be there


Source code
01<?php
02$zip = new ZipArchive;    
03    $res = $zip->open('YourZipFile.zip');
04    if ($res === TRUE) {
05     $zip->extractTo('extracted/');
06     $zip->close();
07     echo 'Unzip was successful';
08     } else {
09     echo 'Unzip was not successful';
10}
11?>

READ MORE

Fashion