Friday, July 31, 2009

Video streaming with php - Uploading process tips.

Most of the websites need the video streaming feature. Today I will share some tips and ideas to handle video uploading process.

Video uploading and streaming requirements.

1. FFMPEG Server. To convert the media into to flash player streaming format (FLV).
2. SSH support.
3. Video uploading and streaming permissions from the hosting service provider.
4. High value bandwidth and storing space. (Depends on your requirement).

Common Errors while uploading the media file and use of ffmpeg.

1. Unable to see any error and file isn't convert.

Verify the path of ffmpeg executable file. Sometimes we have do define the absolute path of ffmpeg in "exec()" or "system()" function.

Use system function to get the last line of the command line tool. Simply echo the response. echo system();

2. File is converting but the values aren't saving properly in the database.

You can handle this error by using the function sleep(20); It will stop the script for a while and then proceed. Sometimes when you upload large files, it usually take time to for conversion. So sleep() function will help you stop the script execution errors and you can handle the confirmation messages more accurately.

Friday, July 17, 2009

Ajax file uploader

I am going to use mootools to write this ajax file uploading script.

Writing CSS:

.loader{
background:url('/images/loader.gif');
text-align:center;
}

You can use any ajax loader image.

Writing the form:
<html>

<head>

<title>Ajax uploader</title>

<link type="text/css" src="css/style.css" />

<script type="text/javascript" src="js/mootools.js"></script>

<script type="text/javascript">

window.addEvent('domready',function(){


$('myform').addEvent('submit', function(e) {

//Prevents the default submit event from loading a new page.

e.stop();

//Empty the log and show the spinning indicator.

var log = $('loading').empty().addClass('loader');

//Set the options of the form's Request handler.

//("this" refers to the $('myform') element).

this.set('send', {onComplete: function(response) {

log.removeClass('loader');

log.set('html', response);

}});

//Send the form.

this.send();

});



});

</script>

</head>

<body>

<div id="loading">

</div>

<form action="upload.php" method="post" enctype="multipart/form-data" id="myform">

Browse: <input type="file" name="upload_file" />

<input type="submit" value="Upload" id="submit" name="submit" />

</form>

</body>

</html>


Write php uploading script:

<?

$file_path="/home/website/www/upload/";

if(!empty($_REQUEST['submit']) &amp;&amp; !empty($_FILES['upload_file'])){


if(move_file_upload($_FILES['upload_file']['tmp_name'],$file_path.$_FILES['upload_file']['name'])){


echo 'File has been uploaded';


}

else{

echo 'Unable to upload file.';

}

}

?>


Don't forget to write your comments. Thanks.

Saturday, July 4, 2009

Htaccess and server configuration.

Today I would like to share information about the apache server and htaccess.

It is usually but possible that mod_rewrite is not enable at your server. Most of the times programmers upload htaccess on a server and when try to check it. It seems like that the htaccess isn't working or server isn't reading anything from the htaccess file.

If you have the access of apache server files, you can verify by checking the mod_rewrite module is enable in httpd.conf.

Make sure another setting in httpd.conf which is AllowOverride None . In this case you will change it to AllowOverride All.

Now we will focus on the server errors due to htaccess.

  1. 500 Internal Error: This can occur if you don't write the htaccess properly. Always write htaccess using Notepad, because wordpad and some other text editors can same the file with different encoding pattern. There can be another issue which is the operating system, keep it in your mind that IIS has different htaccess writing commands.
  2. 403 Forbidden Error: In some cases Google doesn't crawl the site properly that will create load on the server, due to the reason some host stop the crawling of google and you may see 403 Forbidden Error during the loading of website or in error logs. To solve this issue you can modify your htaccess by adding the following files.

    order deny,allow
    deny from 66.249

These are the most common errors while you are uploading or setting up a server.

Friday, July 3, 2009

SimplePie VS Magpie

Simplepie and Magpie both are RSS. Feeds parsers.

According to my experience:















MagpieSimplepie
Light WeightToo Many Files.
Simple ImplementationComplex Implemenation
Easy to modifyDifficult to modify.
Less time to parseDelay in parsing.
Less documentation but enoughGood documented.

Best way to track mysql errors and sql injections.

In the freelancing world. Most of the developers write mysql applications with less security and query control.

Here is a tip I would like to share with the programmers by which you will track the application die queries and its reasons.

According to normal practice most of the developer using the following syntax.

$query="SELECT * FROM foo WHERE id=".$_POST['var'] ;
$result=mysql_query($query) or die (mysql_error());

I would like to focus on the die() function.
You will create a custom function which will send you the following details through email.

1. Script Name.
2. Query.
3. Error.
4. Time.

We will use phpmailer for emailing the information. You can download phpmailer from phpclasses.org.

Error Handling Function:

include phpmailer.php
function error_handle($query,$error,$script_name){

$msg="Mysql Error Report:
Query:".$query."
Error:".$error."
File Name:".$script_name."
Date:".date('d, m, y h:m');

$mail = new PHPMailer();

$mail->From = 'debug@domain.com';
$mail->FromName = 'Auto bug reporter'; //$from;
$mail->Sender = 'debug@domain.com';
$mail->Subject = 'A query die at your website.';
$mail->IsHTML(true);
$mail->Body = $msg;
$mail->AddAddress('tech@domain.com') ;
unset($mail);

}

Now you will write your queries like the following pattern.

$filename=$_SERVER['SCRIPT_FILENAME'];
$query="SELECT * FROM foo WHERE id=".$_POST['var'] ;
$result=mysql_query($query) or die (error_handle($query,mysql_error(),$filename));

### End and enjoy providing support to your clients and also keep an eye at sql injections with this code. You can also advance and modify it according to your need.

Thursday, July 2, 2009

Why not codeigniter.

The love with codeigniter is increasing day by day. It makes me crazy, when I saw the implementation of search engine friendly urls.

After completing a number of projects in codeigniter, I realize that it is the most efficient and suitable framework at this time.

There are 5 Major factors for me due to which I vote +ve for codeigniter.
  1. Opensource.
  2. MVC Based.
  3. Built-in Template Engine.
  4. Built-in classes for emailing and handling content also include captcha class. These are called helpers in CI.
  5. Make easy to create more effective search engine friendly urls by defining routes.
We have not discussed this framework in depth, until you will try it and reply with your experience.

Now I would like to move to question about CI. Most of the programmers raise this question.

Q. How to define constants using 'define("foo","foo-text")' in codeigniter?
A. I always define a simple file which I include in the index.php of codeigniter. It is a very simple thing you can do to handle your define variables. If you look or search codeigniter, it will not guide or provide you any information about it. It is also common that some programmers define variables in the controllers (The executional script in CI).
All rights are reserved. Nobleatom.com
Software Development Services.
Contact me: khubabmazhar596@hotmail.com

Web Design Increase Page Rank Internet blogs DigNow.net web directory1Abc DirectorySeo friendly web directory