在index.php
我有這樣的代碼:運行時我收到錯誤的項目:警告:執行opendir未能打開目錄:未實現
<?php
$pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$) |(\.Gif$)"; //valid image extensions
$files = array();
$curimage=0;
if($handle = opendir("http://newsxpressmedia.com/files/radar-simulation-files")) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){ //if this file is a valid image
//Output it as a JavaScript array element
$files[] = $file;
$curimage++;
}
}
closedir($handle);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>change picture</title>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<style type='text/css'>
#Timer_Countdown{
background:black;
color:yellow;
font-weight:bold;
text-align:center;
}
</style>
<script type = "text/javascript">
function displayNextImage() {
x = (x === images.length - 1) ? 0 : x + 1;
document.getElementById("img").src = images[x];
}
function displayPreviousImage() {
x = (x <= 0) ? images.length - 1 : x - 1;
document.getElementById("img").src = images[x];
}
$json = json_encode($files);
//json = <?php echo $json; ?>
var images = JSON.parse(json);
//var images = <?=json_encode($files)?>;
//var images = [];
var x = -1;
var swap_hours = 0;
var swap_minutes = 0;
var swap_seconds = 5;
var down_counter_hours;
var down_counter_minutes;
var down_counter_seconds;
function initTimer() {
down_counter_hours = swap_hours;
down_counter_minutes = swap_minutes;
down_counter_seconds = swap_seconds;
counter = setInterval(switcher, 1000);
}
function restartCounter() {
down_counter_hours = swap_hours;
down_counter_minutes = swap_minutes;
down_counter_seconds = swap_seconds;
}
function switcher() {
down_counter_seconds--;
if (down_counter_hours <= 0 && down_counter_minutes <= 0 && down_counter_seconds <= 0) {
swapColor();
restartCounter();
}
if (down_counter_seconds <= 0 && down_counter_minutes > 0) {
down_counter_seconds = 60;
down_counter_minutes--;
}
if (down_counter_minutes <= 0 && down_counter_hours > 0) {
down_counter_minutes = 60;
down_counter_hours--;
}
document.getElementById("Timer_Countdown").innerText = down_counter_hours+":"+down_counter_minutes+":"+down_counter_seconds;
}
function swapColor() {
displayNextImage();
}
</script>
<div id="div_hours" class="div_box"></div>
<div id="div_minutes" class="div_box"></div>
<div id="div_seconds" class="div_box"></div>
<div id="div_switcher" class="div_box"></div>
</head>
<body onload = "initTimer()">
<div id="Timer_Countdown"> </div>
<img id="img" src="http://newsxpressmedia.com/files/theme/radar000005.Gif">
<button onclick="displayPreviousImage(); restartCounter()">Previous</button>
<button onclick="displayNextImage(); restartCounter()">Next</button>
</body>
</html>
我的主人的網站是ipage.com 在上的iPage的文件管理器.com我從根目錄中看到目錄文件/ radar-simulation-files。
我正在使用netbeans 8.0.1和xampp來運行localhost apache服務器。
在NetBeans中,當我點擊運行按鈕,它會到此位置:
http://localhost/PhpProject2/index.php
還有,第一圖像上面我看到:
Warning: opendir(http://newsxpressmedia.com/files/radar-simulation-files): failed to open dir: not implemented in C:\xampp\htdocs\PhpProject2\index.php on line 5
我想要做的是讓目錄文件/雷達模擬文件中所有圖像的列表
編輯
這是我現在試圖代碼:
<?php
$username = 'my domain name';
$password = 'my pass';
$basepath = 'domains/newsxpressmedia.com/public_html/';
$handle = opendir("ftp://{$username}:{$password}@ftp.ipage.com/{$basepath}files/radar-simulation-files");
//$imgdir = 'images/'; //Pick your folder
$allowed_types = array('png','jpg','jpeg','gif'); //Allowed types of files
//$dimg = opendir($imgdir);//Open directory
while($imgfile = \readdir(handle))
{
if(in_array(strtolower(substr($imgfile,-3)),$allowed_types) OR
in_array(strtolower(substr($imgfile,-4)),$allowed_types))
/*If the file is an image add it to the array*/
{$a_img[] = $imgfile;}
}
echo "<ul>";
$totimg = count($a_img); //The total count of all the images
//Echo out the images and their paths incased in an li.
for($x=0; $x < $totimg; $x++){echo "<li><img src='" . $imgdir . $a_img[$x] . "' /></li>";}
echo "</ul>";
?>
<!DOCTYPE html>
<html>
<head>
<title>change picture</title>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<style type='text/css'>
#Timer_Countdown{
background:black;
color:yellow;
font-weight:bold;
text-align:center;
}
</style>
<script type = "text/javascript">
function displayNextImage() {
x = (x === images.length - 1) ? 0 : x + 1;
document.getElementById("img").src = images[x];
}
function displayPreviousImage() {
x = (x <= 0) ? images.length - 1 : x - 1;
document.getElementById("img").src = images[x];
}
/* @var $ar type */
var images = <?php echo \json_encode($imgfile) ?>;
//$json = json_encode($imgfile);
//json = <?php echo $json; ?>
//var images = JSON.parse(json);
//var images = <?=json_encode($files)?>;
//var images = [];
var x = -1;
var swap_hours = 0;
var swap_minutes = 0;
var swap_seconds = 5;
var down_counter_hours;
var down_counter_minutes;
var down_counter_seconds;
function initTimer() {
down_counter_hours = swap_hours;
down_counter_minutes = swap_minutes;
down_counter_seconds = swap_seconds;
counter = setInterval(switcher, 1000);
}
function restartCounter() {
down_counter_hours = swap_hours;
down_counter_minutes = swap_minutes;
down_counter_seconds = swap_seconds;
}
function switcher() {
down_counter_seconds--;
if (down_counter_hours <= 0 && down_counter_minutes <= 0 && down_counter_seconds <= 0) {
swapColor();
restartCounter();
}
if (down_counter_seconds <= 0 && down_counter_minutes > 0) {
down_counter_seconds = 60;
down_counter_minutes--;
}
if (down_counter_minutes <= 0 && down_counter_hours > 0) {
down_counter_minutes = 60;
down_counter_hours--;
}
document.getElementById("Timer_Countdown").innerText = down_counter_hours+":"+down_counter_minutes+":"+down_counter_seconds;
}
function swapColor() {
displayNextImage();
}
</script>
<div id="div_hours" class="div_box"></div>
<div id="div_minutes" class="div_box"></div>
<div id="div_seconds" class="div_box"></div>
<div id="div_switcher" class="div_box"></div>
</head>
<body onload = "initTimer()">
<div id="Timer_Countdown"> </div>
<img id="img" src="http://newsxpressmedia.com/files/theme/radar000005.Gif">
<button onclick="displayPreviousImage(); restartCounter()">Previous</button>
<button onclick="displayNextImage(); restartCounter()">Next</button>
</body>
</html>
我已經將文件上傳到我的主機域名ipage.com文件管理 然後我瀏覽到:
它開始計數回定時器,但然後停止1
然後我在網站上做:檢查元件 而在控制檯我看到錯誤:
遺漏的類型錯誤:無法讀取空
的特性「長度」上線23
某處有問題,PHP代碼,應該讓所有的圖像文件,並把它們在數組中。
現在編輯我的問題與我現在嘗試什麼,我得到什麼錯誤,我越來越。 – 2014-11-02 22:05:21