-2
我是一个php noob,我只是从我在网上找到的其他脚本中创建了一个小脚本。它从名为“随机”的文件夹中选取3个随机图像并显示它们。我的随机代码不能脱机工作
虽然我在网上运行该脚本它工作,但是当我尝试在XAMPP脱机运行它,我得到这个错误:
注意:未定义的变量:用C random2:\ XAMPP \ htdocs中\铎\ finaleasd2 69线上的.php
这是图像被命名为变量的行。 我认为这是由于脚本在离线时不能获得文件夹名称,但我不确定:出了什么问题? :)
顺便说一句,这是剧本和第69行是而 {(我知道,这是一个烂摊子!d)($ random2 || $ random2 == $ random1!)
谢谢你你的帮助和时间! :)
<?php function RandomFile($folder='', $extensions='.*'){
// fix path:
$folder = trim($folder);
$folder = ($folder == '') ? './' : $folder;
// check folder:
if (!is_dir($folder)){ die('invalid folder given!'); }
// create files array
$files = array();
// open directory
if ($dir = @opendir($folder)){
// go trough all files:
while($file = readdir($dir)){
if (!preg_match('/^\.+$/', $file) and
preg_match('/\.('.$extensions.')$/', $file)){
// feed the array:
$files[] = $file;
}
}
// close directory
closedir($dir);
}
else {
die('Could not open the folder "'.$folder.'"');
}
if (count($files) == 0){
die('No files where found :-(');
}
// seed random function:
mt_srand((double)microtime()*1000000);
// get an random index:
$rand = mt_rand(0, count($files)-1);
// check again:
if (!isset($files[$rand])){
die('Array index was not found! very strange!');
}
// return the random file:
return $folder . "/" . $files[$rand];
}
//assegna i nomi delle variabili ai file
$random1 = RandomFile("random");
while (!$random2 || $random2 == $random1) {
$random2 = RandomFile("random");
}
while (!$random3 || $random3 == $random1 || $random3 == $random2) {
$random3 = RandomFile("random");
}
//la parte dedicata alla creazione dei testi alternativi partendo da un file di testo
$quotesfile = "quotes.txt"; //Relative path to and the filename of the file that contains your quotes.
$array = @file("$quotesfile");
// Crea un array con le citazioni
$quote = rand(0, count($array)-1);
$titolo = array_rand($array, 3);
// la parte sotto crea un div con dentro due immagini statiche, i lati della panchina, e quattro caricate a caso. le immagini hanno
// come titoli le variabili estratte casualmente dall' array di nome array preso dal file di testo di prima
?>
尽管有通知,脚本是否仍然显示图像? –
不是,图像显示为破损或丢失 – tommaso
那么,我可以问你有关'未定义变量'的问题吗? – Bobby