-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