Gốc > Thế giới Tin học > Lập trình > PHP >
[PHP] Hiển thị hình ảnh Random ở chữ ký.
Bạn tạo 1 thư mục images chứa các hình ảnh cần hiển thị và 1 file random.php có nội dung như sau:
Để hiển thị những hình ảnh đó bạn chỉ cần chèn dòng sau vào chữ ký của bạn:
Chúc bạn thành công !
Lê Khắc Thành Đạt @ 13:21 29/06/2011
Số lượt xem: 577
PHP Code:
<?php
$folder = 'images/'; //tên thư mục mà bạn lưu chứa hình ảnh.
$exts = 'jpg jpeg png gif';
$files = array(); $i = -1;
if ('' == $folder) $folder = './';
$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
foreach($exts as $ext) {
if (preg_match('/\.'.$ext.'$/i', $file, $test)) {
$files[] = $file;
++$i;
}
}
}
closedir($handle);
mt_srand((double)microtime()*1000000);
$rand = mt_rand(0, $i);
header('Location: '.$folder.$files[$rand]);
?>
$folder = 'images/'; //tên thư mục mà bạn lưu chứa hình ảnh.
$exts = 'jpg jpeg png gif';
$files = array(); $i = -1;
if ('' == $folder) $folder = './';
$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
foreach($exts as $ext) {
if (preg_match('/\.'.$ext.'$/i', $file, $test)) {
$files[] = $file;
++$i;
}
}
}
closedir($handle);
mt_srand((double)microtime()*1000000);
$rand = mt_rand(0, $i);
header('Location: '.$folder.$files[$rand]);
?>
PHP Code:
[img]http://www.yoursite.com/random.php[/img]
Lê Khắc Thành Đạt @ 13:21 29/06/2011
Số lượt xem: 577
Số lượt thích:
0 người
 
- [PHP] Chương trình php đầu tiên (29/06/11)
- [PHP] Hiển thị hình ảnh Random ở chữ ký. (29/06/11)
- [PHP] Chương trình php đầu tiên (29/06/11)
- phpDesigner 2008 v6.0.2 (30/06/10)
- Ebook PHP 5 (30/06/10)
Các ý kiến mới nhất