Here are a few ways you can list all the files in a specific directory. In the examples below, it is the same directory as where the PHP application is.

Using the PEAR library

To use the PEAR library to accomplish this, you need to make use of the File_Find class. There is a method search() that you can call statically to perform a search of a directory, which returns the results in an array.

Code:

<?php
require_once ‘File/Find.php’; // include the PEAR class

$files = File_Find::search(“\..+$”,getcwd()); // getcwd() prints the current working directory; the first parameter contains a “regular expression”
sort($files); // sorts the files in the array in alphabetical order

echo “<ul>”;
foreach($files as $file) echo “<li>” . basename(htmlspecialchars($file)) . “</li>”; // basename makes sure the returned string is not the absolute path of the file (so not this: /home/user/public_html/and/so/on)
echo “</ul>”;
?>

Using standard PHP functions

Using standard functions is just as easy:

<?php
$dir = opendir(getcwd()); // getcwd() prints the current working directory

echo “<ul>”;

while(($file = readdir($dir)) !== false) // the readdir() function advances to the next file in the resource ($dir) and the while loop cycles through each item
{
if(preg_match(“/\.[a-zA-Z0-9\-_]+$/”,$file)) // the first parameter contains a “regular expression”
{
echo “<li>” . $file . “</li>”;
}
}

echo “</ul>”;

closedir($dir);
?>

What are regular expressions?

Regular expressions are a powerful way to find matches in strings, as well as pattern matches. The most complicated part of using regular expressions are the use of “metacharacters”, which are characters which have a specialised purpose in regular expression syntax. Here is an explanation of the two regular expressions used above:

  • Note: When using preg_match(), regular expressions have to be within the forward-slash characters, so PHP knows where the start and end of a regular expression string is.
  • \. the backslash tells PHP to take the period character literally, because it is otherwise a reserved character (metacharacter). In the first regular expression (the code using the PEAR library), you’ll actually see two period characters – \.. – this is because I want the first character to be a full stop, then any character the . is a metacharacter which means “any character to match – a, b, c, f, z – etc.”.
  • [a-zA-Z0-9\-_] characters within these types of brackets are “character groups”, so to speak. So in this case, I want to match file names which have a period character in them, with any form of a-z, A-Z, 0-9, _ and – character in them. The backslash before the – is required in this context because it otherwise designates the range (e.g. A-Z, A-C, F-Z and so on).
  • + is a metacharacter which means “1 or more times”. In other words, I want at least one character to match after the period character (so, for example, a.jpg would be a match)
  • $ is a metacharacter which means “end of string” – in other words, I want .jpg to be a match only if it is at the end of the file name string
  • . is a metacharacter which means “any character” to match – a, b, c, f, z, 0, 1, 2 – and so on.

Hope this helps.

 

, , , , , , ,

Leading cloud hosting providers, Rackspace, commissioned the eGeneration Cloud study in association with the centre for Creative and Social Technology (CAST) at Goldsmiths University of London to look into how cloud services have really changed the way we work and play in every aspect of our existence.

The research that has come from this study reveals that (without being fully aware of it) a significant 66% of British users are relying on cloud computing services every day.

eGeneration Cloud

Infographic by Rackspace

Read more about the study here: http://www.rackspace.co.uk/generationcloud

Cloud Hosting

What is the GRUB Bootloader?

As basic as it sounds, the GRUB loader is used with Linux distributions such as Ubuntu in order to allow you to switch between different hard drive partitions that have different operating systems installed. Partitioning is the system of separating space on a hard drive for different media or operating systems. You can even partition your hard drive using Disk Management in Windows in order to store music, for example.

How to restore Windows MBR?

If you intend on installing Ubuntu and dual-boot between Ubuntu and Windows, the GRUB bootloader will be installed. To remove the Ubuntu GRUB bootloader, you will need to reinstall the Windows MBR which can be done with a Windows installation disc. Follow the instructions on Microsoft’s Support page to do this, but when it tells you to type and execute bootrec.exe, type: bootrex.exe /fixmbr. This will restore the Windows MBR. Now you will be able to delete the Ubuntu partition via Windows “Disk Management” utility (by right-clicking on Computer from the Start menu and selecting Manage).

To get vim to auto indent new lines, ensure you are out of insert mode (by pressing the Esc key) and entering:

:set ai

Hope this helps.

Affects MacBook Pro 2011 (model identifiers: 8,1 8,2 8,3)

I had the same issue. I don’t know exactly why the problem is occurring but it is a problem with Ubuntu 11.04 as well as software such as GParted that use Debian. As far as I read it is down to Debian that is causing this issue. To go around this issue, you need to copy the .iso file image of Ubuntu onto a USB drive. So you’ll need a spare USB drive available. Make sure you burn any important data on that USB drive onto a disc or to a safe place – but not the hard drive and/or partitions you will be erasing!

First, rename the Ubuntu ISO image in the Downloads folder (or where ever you saved it) to just ubuntu.iso.

Next, go to Disk Utility (found in the Utilities folder or use Spotlight in the top-right corner) and find the Disk Identifier for the USB device. To do this, when Disk Utility is open, click on the USB drive (not the partition(s) on the USB drive prior to erasing) and then click the Info button up top. You should find a section for “Disk Identifier”, which will have a value like disk0 or disk1. Copy the disk identifier value (CMD + C, that is). Now click on each partition (or the partition if you just have one) on the USB drive and click the Unmount button at the top of the application interface. If you don’t do this, when you execute the command below it will simply say “Resource busy” (referring to the USB drive and the mounted partitions).

Next, go to a Terminal window (found in the Utilities folder or via spotlight search) and copy and paste the following command:

dd if=~/Downloads/ubuntu.iso of=/dev/diskN bs=1m

Change N to the number of your disk identifier, or alternatively use your arrow keys if you have already pasted the Terminal command, to change diskN to whatever value you copied from the Disk Utility (for example, it may be disk1).

Once executed, it will seem like the Terminal has frozen. Wait for it to complete. Once it’s completed, you’ll see it return control back to you and telling you how much data was transferred to the USB drive.

Now make sure the Ubuntu disc is in the disc drive and restart your computer while pressing down the C key to boot into the disc. Follow the usual steps to get to Try ubuntu without installing. After this point, it will be using the USB drive data to show you the desktop and for the installation procedure. You’ll notice it’s much faster installation-wise because it is being done via the USB drive.

Hope this helps!

The clear:left, clear:right, clear:both (clear selector) is used to clear CSS floats or to prevent a float from affecting another HTML element such as another box if you have one box floated to the left or right or page content. When you use the clear selector in this context, the selector/box that is cleared will not be affected by the float and will appear below the floated box instead of next to it.

Additionally, the clear selector may be used to stop any float continuation. If you use floats and you find some content or a box you’ve created using CSS is floating when you don’t want it to, use clear:left to stop a float:left and likewise clear:right to stop a float:right from continuing. If you’re unsure and you want to stop floats completely, using clear:both is fine. However, clear:both clears both sides, obviously.

Note: This is primarily for the Lenovo C200 AIO but may work for other Intel/NVIDIA hybrid graphics systems. Disclaimer: Instructions / information / advice below should be taken at your own risk and responsibility.

I have a Lenovo C200 All in One. I decided to install Ubuntu 11.04 Natty Narwhal on it and mostly everything went well; wireless was detected out of the box, sound too but Ubuntu was displaying a 1024×768 resolution and had no bigger resolutions available in the Monitor settings. Additionally, the new Unity interface was not being used because the NVIDIA proprietary drivers were activated but not in use (and they do not work, don’t install them – NVIDIA proprietary drivers don’t support hybrid graphics systems. If you have installed the proprietary driver and it is activated, Ubuntu won’t display anything upon reboot. Instructions on how to uninstall the proprietary driver are here if you have installed them through Additional Drivers). There are the free and open source nouveau drivers which apparently support basic 3D acceleration but there are also experimental nouveau “3D acceleration” drivers available through Additional Drivers. When I removed the proprietary NVIDIA drivers through Additional Drivers, after a restart, the Unity interface was active. So I presumed I was using the standard nouveau drivers which support basic 3D acceleration. So if you want the Unity interface and GPU acceleration, remove the proprietary drivers through Additional Drivers that may be active but not in use. Additionally, you can try out the experimental nouveau drivers too (but make sure you restart your computer after uninstalling the proprietary drivers before installing the experimental ones). Just to state, I am unsure whether GPU acceleration is active through the NVIDIA ION 2 GPU or not (I presume because the Unity interface is active), but I’m not too technically literate with Ubuntu so I wouldn’t know how to find out.

To sort the resolution out, open the Terminal application and execute the following command:

xrandr -s 1366×768

NOTE: Change the resolution to what your resolution can natively support. In the case of the Lenovo C200 All in One with Intel GMA 3150 and NVIDIA ION 2 hybrid graphics, according to dabs.com specifications I purchased it from, it supports up to 1366×768. If you have a different computer, you may find supported resolutions by typing xrandr into the Terminal on it’s own or find through specification information for your computer. I believe the reason the native resolution isn’t being detected and used by default is because, for me, when I type xrandr, it displays two different monitors (it appears – I wouldn’t know exactly – I’m no expert). One says LVDS1 and the other VG1. I could be wrong though.

To make this resolution be set by default, go to Monitor settings and click the button on that window titled Make Default (near bottom left of window).

Hope this helps.