1. Installaion
   ( How to Install PHP and MySQL Under Windows XP ) 
    http://heliotropicsystems.com/pubs/TSa092005.pdf
    http://www.builderau.com.au/program/mysql/print.htm?TYPE=story&AT=339271632-
    339028784t-320002018c   
   ( How to configure LAMP )
    http://lamphowto.com/
    http://www.mysql-apache-php.com/
    
    There are good sources to help installing LAMP and WAMP. 
2. PHP Configuration (php.ini)
   Sometimes, We need to modify this file to set up our system. Because PHP stores 
   all kinds of configuration in this file. This file is in the directory where we 
   installed PHP.  
   Following is good source to understand how to use php.ini file
   http://www.washington.edu/computing/web/publishing/php-ini.html
   
3. Uploading Files to MySQL Database
   This is very interesting skill and sometimes very useful.. So, I wanna mention 
   here.
   Using PHP to upload files into MySQL database sometimes needed by some web 
   application. For instance for storing pdf documents or image. 
   A. First, Make the teable for the upload files
      id, name, type, size, content
      We can use one of three BLOB data types for column content. 
      They are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB
      BLOB is limited to store up to 64 kilobytes of data and MEDIUMBLOB is to store 
      up to 16 megabytes.
      ( Example )
      CREATE TABLE upload (
       id INT NOT NULL AUTO_INCREMENT, 
       name VARCHAR(30) NOT NULL,
       type VARCHAR(30) NOT NULL,
       size INT NOT NULL,
       content MEDIUMBLOB NOT NULL,
       PRIMARY KEY(id)
      ); 
       
   B. Second, uploading a file to MYSQL DB. 
      uploading the file to the server then read the file and insert it to MySQL.
      Using post method, and then using file as input type. Bellow is the example
      
      
      And then we can use $_FILES to upload the file to MySQL 
      $_FILES['userfile']['name']
      $_FILES['userfile']['type']
      $_FILES['userfile']['size']
      $_FILES['userfile']['tmp_name']
      $_FILES['userfile']['error']
     
      Following is the example of uploading the file to MySQL
      $fileName = $_FILES['userfile']['name'];
      $tmpName  = $_FILES['userfile']['tmp_name'];
      $fileSize = $_FILES['userfile']['size'];
      $fileType = $_FILES['userfile']['type'];
      $fp = fopen($tmpName. 'r');
      $content = fread($fp, filesize($tmpName));
      $content = addslashes($content);
      fclose($fp);
      $query = "INSERT INTO upload (name, size, type, content) VALUES 
      ('$fileName', '$fileSize', '$fileType', '$content')";
      mysql_query($query) or die ('Error, query failed');
  Wow! I'm feeling there are so many interesting techniques in PHP+MySQL....
  Continue to next
Subscribe to:
Post Comments (Atom)
 
No comments:
Post a Comment