Friday, June 1, 2012

Codeigniter flv,wmv uploading gives error “Invalid file type”


It gives “The filetype you are attempting to upload is not allowed.” error when I was trying to upload flv and wmv files using codeigiter “upload” library.
I was sure about $config array. But this error was there when I was trying video upload.
My $config settings were as follows.
//CodeIgniter Code
$configVideo['upload_path'] = './upload/video';
$configVideo['max_size'] = '10240';
$configVideo['allowed_types'] = 'avi|flv|wmv|mp3';
$configVideo['overwrite'] = FALSE;
$configVideo['remove_spaces'] = TRUE;
$video_name = $_FILES['video']['name'];
Solution:  
Open mimes.php file in config folder
Add folowing two lines into the $mimes array
'wmv'=>array('video/wmv', 'video/x-ms-wmv', 'flv-application/octet-stream', 'application/octet-stream'),
 'flv' =>array('video/flv', 'video/x-flv', 'flv-application/octet-stream', 'application/octet-stream'),
Hope this will help you out..
Thanks for visiting my blog.. 


Monday, May 28, 2012

Php mysql collation change script for tables and fields

<?php

$host = 'localhost';
$username = 'root';
$password = '';
$dbname = 'dbname';

$db = mysql_connect($host, $username, $password);
  mysql_select_db($dbname);

$mysqldatabase = 'dbname';
$collation = 'CHARACTER SET utf8 COLLATE utf8_general_ci';

echo '<div>';
mysql_query("ALTER DATABASE $mysqldatabase $collation");

$result = mysql_query("SHOW TABLES");

$count = 0;
while($row = mysql_fetch_assoc($result)) {
$table = $row['Tables_in_'.$mysqldatabase];
mysql_query("ALTER TABLE $table DEFAULT $collation");
$result1 = mysql_query("SHOW COLUMNS FROM $table");
$alter = '';
while($row1 = mysql_fetch_assoc( $result1)) {
if (preg_match('~char|text|enum|set~', $row1["Type"])) {
if(strpos($row1["Field"], 'uuid')){
// why does this not work
}else{
$alter .= (strlen($alter)?", \n":" ") . "MODIFY `$row1[Field]` $row1[Type] $collation" . ($row1["Null"] ? "" : " NOT NULL") . ($row1["Default"] && $row1["Default"] != "NULL" ? " DEFAULT '$row1[Default]'" : "");
}
}
}
if(strlen($alter)){
$sql = "ALTER TABLE $table".$alter.";";
echo "<div>$sql\n\n</div>";
mysql_query($sql);
}
$count++;
}
echo '</div>';

?>

Monday, April 30, 2012

SQL Keys


Important SQL Keys
SQL Keys:
In SQL, keys are used to maintain referential integrity among relations. Put simply, this means keys allow tables to reference each other, and each reference will be “correct” every time. Referential integrity also prevents records from being “dangled” or “orphaned” by another record that has been deleted. There are lots of SQL keys which are widely used in SQL environment in which are all keys some are defined as follows:
Primary Key:
 Primary key are those key which are uniquely defined in a database table or we can say that a database table can contain only one primary key. A primary key is used to uniquely identify each row in a table. It can either be part of the actual record itself, or it can be an artificial field (one that has nothing to do with the actual record). A primary key can consist of one or more fields on a table. When multiple fields are used as a primary key, they are called a composite key. Primary Key enforces uniqueness of the column on which they are defined. Primary Key creates a clustered index on the column. Primary Key does not allow Nulls.
Example: Creating Primary Key in database table
create table PrimarkeyTest  // primarykeytest is table name
(
id int not null primary key,// create primary key constraints on id column
name varchar(20)

)
Foreign Key:
                A foreign key is a field (or fields) that points to the primary key of another table. The purpose of the foreign key is to ensure referential integrity of the data. In other words, only values that are supposed to appear in the database are permitted.
Example: Creating foreign key in database table
create table foreignkeytest // foreignkeytest is a table name
(
--// create foreign key  which references to primarykeytest table id column
fid int references  PrimarkeyTest(id),
name varchar(20)
)
Unique Key:
In relational database design, a unique key can uniquely identify each row in a table. A unique key comprises a single column or a set of columns. No two distinct rows in a table can have the same value in those columns if NULL values are not used. Depending on its design, a table may have arbitrarily many unique keys but at most one primary key.
Unique keys do not enforce the NOT NULL constraint in practice. Because NULL is not an actual when two rows are compared, and both rows have NULL in a column, the column values are not considered to be equal. Thus, in order for a unique key to uniquely identify each row in a table, NULL values must not be used. However, a column defined as a unique key column allows only one NULL value, which in turn can uniquely identify that row.
Example: Creating Unique Key in database table
create table Uniquekeytest
(
--// create unique key  in Uniquekeytest table uid column
uid int unique,
name varchar(20)

)
Candidate Key:
A Candidate Key can be any column or a combination of columns that can qualify as unique key in database. There can be multiple Candidate Keys in one table. Each Candidate Key can qualify as Primary Key.
Composite Key:
Composite key is nothing more than a primary key which consist of more than one column to uniquely identify row of table. That is composite key is a combination of more than one column to uniquely identify the row of table.
Example: Creating Composite key With Create command
----DEMONSTRATION OF CREATING COMPOSITE KEY WITH CTREATE TABLE COMMAND-----
CREATE TABLE TEST_COMPOSITE
(
 ID INT NOT NULL,
 [UID] INT NOT NULL,
 NAME VARCHAR(20)
 CONSTRAINT CK_TEST_COMPOSITE PRIMARY KEY (ID,[UID])
)

Sunday, February 12, 2012

Word press Directory URL Tags

home_url() Home URL http://www.example.com
site_url() Site directory URL http://www.example.com or http://www.example.com/wordpress
admin_url() Admin directory URL http://www.example.com/wp-admin
includes_url() Includes directory URL http://www.example.com/wp-includes
content_url() Content directory URL http://www.example.com/wp-content
plugins_url() Plugins directory URL http://www.example.com/wp-content/plugins
wp_upload_dir() Upload base URL in ['baseurl'] entry of returned array http://www.example.com/wp-content/uploads

Tuesday, February 7, 2012

Email Validation Through PHP

function isValidEmail($email){
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}

How to change the PHP version for subfolders or subdomains

  How to change the PHP version for subfolders or subdomains Setting a specific PHP version for a specific websites, subfolders or subdomain...