Showing posts with label file. Show all posts
Showing posts with label file. Show all posts

Saturday, September 12, 2015

PHP convert doc file to text file

PHP allows file uploads, file write, copy, move, delete and also it supports conversion of one file format to another.
In this example we will see how a doc file is converted to a text file.

function doc2text($file)
{
$file     = $directory.'/'.$filename;
$fileinfo = pathinfo($filename);
$content  = "";
// doc to text
$content = shell_exec("antiword -m UTF-8.txt -t $file");
return $content;
}

 The usage of the function is as follows:

  $file = "documents/files/doc/test.doc";
  doc2text($file);

PHP get extension of a file

PHP supports file uploads. user can design a system where he can allow users to upload files with specific extension type.
In many website we have the provision to upload files with specific file extension.
For example facebook we can upload file with extension jpeg, jpg,png etc for the profile picture.

Similarly it can be achieved in PHP. Following function returns you the extension of the given file type.

function getExtension($str)
{
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

$filename = "images/image01.jpeg" ;
$extension=getExtension($filename);
echo "Extension of the file is: ".$extension;

The output of the above function call will be:

Extension of the file is: jpeg

MS SQL : How to identify fragmentation in your indexes?

Almost all of us know what fragmentation in SQL indexes are and how it can affect the performance. For those who are new Index fragmentation...