Postingan Yang Kamu Cari

Sabtu, 27 Maret 2010


A simple method for centering divs that I usually use is:
The CSS
  1. #content {  
  2.    width: 800px;  
  3.    margin: 0 auto;  
  4. }  
The HTML
  1. <div id="content"> something here div>  
What this does is creates a div 800 pixels wide then sets the top and bottom to 0 pixels then sets the left and right margins to be auto. This makes the browser give the div equal spacing on either side.
by John Email
This was something I quickly threw together to randomise a folder of photos.
Basically you put all your photos in one folder, it then randomly copies them to an output folder with a new file name.
This was used for randomising photos for a photo DVD at a party.
Its fine for basic things. If you plan on using it for a website or something I would suggest tweaking the code a bit.
Also note that it was only written to handle .jpg files. It wouldn't be too hard to modify it though.
Feel free to use the code as you wish.
// Make sure the user has passed in values via the command line
if( !isset($argv[0]) || !isset($argv[1]) || $argv[0] == "" || $argv[1] == "") 
{

// If there are no values then display a usage message and exit
echo "\n**** Photo Randomiser ****\n\nUsage:\n\tphp photo_rand.php [SOURCE_PATH] [DEST_PATH]\n\n";
exit;
}
// Get the in and out dir
$in_dir = $argv[0];
$out_dir = $argv[1];
// Create an array for storing the file list
$file_list = array();
echo "/nreading files";
// Make sure the directory is valid
if (is_dir($in_dir)) {
// Open the directory
if ($dh = opendir($in_dir)) {

// Loop through all the files in the directory
while (($file = readdir($dh)) !== false) 
{
// Make sure we don't include . and ..
if( $file != "." && $file != ".." ) 
{
// Add the current file to the file list
$file_list[] = $file;
}

}

closedir($dh);
}
}
echo "
shuffling";
// Shuffle the array
shuffle($file_list);
echo "
copying";
$file_count = 1;
// Loop through the file array list
foreach($file_list as $value) {
// Copy the file to the output dir with its new name. I use a number for the output file to keep the files in their shuffled order.
copy($in_dir . $value, $out_dir . $file_count . ".jpg");

$file_count++;

}
echo "
finished";
?>This should work in all major browsers including IE7, IE8, Firefox, Chrome and Safari.

Tidak ada komentar: