Archive for August, 2009

Google Gmail Available On Butterfly Media Romania

31 August 2009

As a hosting company, I always try to leverage the clients’ needs over smart and intelligent software or platforms. A lot of clients ask for email accounts and more than often they go above their quota. No problem with this so far, but if Google Apps offer access to their Google Mail account, all on your server and with your own branding, why not?

Gmail Logo

After having successfully installed Gmail on one of my clients’ accounts, Butterfly Media Romania offers full support for Gmail on its hosting plans. And, yes, you can benefit from about 7.5 GB of email space, the amount that’s currently available with Gmail.

All the features included in Gmail, such as the contact chooser, the undo send feature, and the colourful labels. A full list of what Gmail offers can be found here.

All hosting plans starting from 4,99EUR. Read more on Butterfly Media Romania.

9 Methods To Read Files In A Folder Using PHP

22 August 2009

Method 1.

This is the simplest way to list files in a folder:

<?php
$dir = ".";
$dh = opendir($dir);
while (($file = readdir($dh)) !== false) {
echo $file.'<br />';
}
closedir($dh);
?>

In order to add links to the files in the folder, we modify the code as below. Warning, this might pose some serious security threats if publicly exposed.

<?php
$dir = ".";
$dh = opendir($dir);
while (($file = readdir($dh)) !== false) {
echo '<a href="'.$file.'">'.$file.'</a><br />';
}
closedir($dh);
?>

Method 2.

Another way to read the files would be:

<?php
$dir = ".";
$dh = opendir($dir);
$count=0;
while (($file = readdir($dh)) !== false) {
$count++;
if(substr($file,0,1) != ".") {
echo $file.'<br />';
}
}
?>

The line if(substr($file,0,1) != ".") ensures that no .htaccess or .htpasswd file will be read.

Method 3.

The third method of reading and linking files in a directory would be:

<?php
$current=getcwd();
$directory=basename($current);

$dir = '.';
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] =$filename;
}
// let's get rid of the '.' and the '..' parent and ancestor files
$t=array_slice($files,2);
// let's get rid of the index.php file which does the reading
$f=array_search('index.php',$t);
unset($t[$f]);

print('<a href=".">Back</a><br />');
foreach($t as $key => $value) {
echo('<a href="'.$value.'">'.$value."</a><br />");
}
closedir($dh);
?>

Method 4.

The fourth method is the shortest of them all:

<?php
$dir = '.';
$files = scandir($dir);
//print_r($files);

$num = count($files);
for($n=0; $n<$num; $n++) {
echo $files[$n].'<br />';
}
?>

I left print_r($files); in place but commented in order to show the directory array.

Method 5.

This method resembles phpMyAdmin’s way of listing files with an icon for folders and files. Further customization could show all file types, such as images, archives, php files, html files, css files, and so on. Notice how the ls_recursive() function can be nicely tucked away in a functions file.

<?php
function ls_recursive2($dir) {
if(is_dir($dir)) {
$files = scandir($dir);
foreach ($files as $file) {
$currentfile = $dir."/".$file;
$last_dir = "";
$count = substr_count($currentfile, '/');
$minus_count = substr_count($_SERVER['DOCUMENT_ROOT'], '/');
$count -= ($minus_count + 2);

for($p = 0; $p<$count; $p++) {
$last_dir .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}

if(is_dir($currentfile)) {
if($file != '.' && $file != '..') {
$last_dir .= "<img src='images/folder.gif' alt='' align='middle' width='16' height='16' border='0'>&nbsp;<a href=\"".$currentfile."\">".substr($currentfile, strrpos($currentfile, '/'))."</a><br />";
echo $last_dir;
ls_recursive2($currentfile);
}
}
else {
$last_dir .= "<img src='images/file.gif' alt='' align='middle' width='16' height='16' border='0'>&nbsp;<a href=\"".$currentfile."\">".substr($currentfile, strrpos($currentfile, '/'))."</a><br />";
echo $last_dir;
}
}
}
}
ls_recursive2('.');
?>

Method 6.

Again a nice function for displaying both files in folders and files outside, a remake of the first method:

<?php
function listFolder($path) {
$dir_handle = opendir($path) or die("Unable to open $path");

$dirname = end(explode("/", $path));

echo ("<li>$dirname\n");
echo "<ul>\n";
while (false !== ($file = readdir($dir_handle))) {
if($file!="." && $file!="..") {
if(is_dir($path."/".$file)) {
listFolder($path."/".$file);
}
else {
echo "<li>$file</li>";
}
}
}
echo "</ul>\n";
echo "</li>\n";

closedir($dir_handle);
}
echo '<ul>';
listFolder('.');
echo '</ul>';
?>

Method 7.

Unlike the methods above, this one counts files of a certain extension (in this case, gifs):

<?php
$d = opendir('.');
$count = 0;
while(($f = readdir($d)) !== false)
if(ereg('.gif$', $f))
++$count;
closedir($d);
print "Files=$count";
?>

Method 8.

This method shows how many files (not folders) are in a directory:

<?php
function num_files($directory) {
    return count(glob($directory."*.*"));
}
echo num_files('');
?>

Method 9.

The ninth method adds an interesting feature, file upload. While reading the files in a folder, the script has the capacity to upload a new file in the current directory.

<?php
if (isset($_POST['submit'])) {
copy($_FILES['file']['tmp_name'], $_FILES['file']['name']);
}

$dir=opendir(".");
$files=array();
while (($file=readdir($dir)) !== false) {
if($file != "." and $file != ".." and $file != "index.php") {
array_push($files, $file);
}
}
closedir($dir);
sort($files);

foreach ($files as $file)
print "<a href='$file'>$file</a><br />";
?>
<form action="<?php echo $PHP_SELF ?>" enctype="multipart/form-data" method="POST">
Add a new file: <input type="file" name="file" />
<input type="submit" name="submit" value="Upload file">
</form>

That’s all!

Notice that all examples use ‘.’, which means the curent directory. By using ‘/’ these functions would scan the parent directory.

Stars Fly-Through Video Experiment

21 August 2009

A new video project in 3D Studio Max, this time a fly-through experiment.

star-texture-capture star-texture-screenshot

Here are some video renders, one using normal motion blur, the other one using an excessive blur (together with some rendering errors, when the particle hits the camera, and motion blur is out of FOV). Be sure to watch them in HD quality.

[video]http://www.youtube.com/watch?v=hPsfaIl9Bhs[/video]

[video]http://www.youtube.com/watch?v=B-3DdCS7YIk[/video]

Download the MAX project and the .mat file here.

How To Add A Menu To Whiskey Air Theme

21 August 2009

After realizing my pages got hidden in the big sidebar, I decided to move them and the search box just below the header. A ul/li combination did the trick:

Here’s the CSS style for it. Add it in style.css.

/* Top menu: pages */
#ja-botnav {
background: #CCC;
clear: both;
margin: -2px 0;
padding: 5px 0;
text-align: right;
margin-top: 8px;
}

#ja-botnav ul {
margin: 0;
padding: 0;
}

#ja-botnav li {
margin: 0;
padding: 0 10px;
display: inline;
vertical-align: middle;
}

#ja-botnav li a {
color: #999999;
font-size: 9pt;
}

#ja-botnav li a:hover, #ja-botnav li a:active, #ja-botnav li a:focus {
color: #FFFFFF;
}

And here is the HTML to be added inside the header div:

<div id="ja-botnav">
<ul>
< ?php wp_list_pages('title_li=');?>
</ul>
</div>

If you’re too lazy to do it, download here Whiskey Air 0.9.1 with top menu. Updating Whiskey Air from 0.9 to 0.9.1 is simple. Just replace header.php, footer.php and style.css with the ones in the archive. Don’t forget to carry over any change and addition you’ve made to your Whiskey Air theme.

See here the Whiskey Air theme in action:

Do you have your blog powered by Whiskey Air? Share it here and I’ll share some link love.

Butterfly Media Romania Catalog

20 August 2009

Butterfly Media Romania decided to release a graphics and a web showcase catalog. It will be available both as a PDF downloadable document and as a hard-cover book. I have lots of works to make public, and I try to this the most attractive way possible. Here are the 2 covers:

cover-web

cover-graphics

And it’s alright to say catalog instead of catalogue. Read here.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes