duandan9680 2014-11-02 18:52
浏览 573

运行项目时我收到错误:警告:opendir无法打开dir:未实现

In index.php I have this code:

<?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">&nbsp;</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>

My host website is ipage.com In the filemanager on ipage.com i see the directory files/radar-simulation-files from the root directory.

I'm using netbeans 8.0.1 and xampp to run localhost apache server.

In NetBeans when I click the run button it's going to this location:

http://localhost/PhpProject2/index.php

And there, above the first image I see:

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

What I want to do is to get a list of all images in the directory files/radar-simulation-files

EDIT

This is the code i tried now:

<?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 = eaddir(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">&nbsp;</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>

I have uploaded the file to my host domain ipage.com filemanager I'm then browsing to:

My site

It start counting back the timer but then stop on 1

Then i'm doing on the website: Inspect element And in the console i see error:

Uncaught TypeError: Cannot read property 'length' of null

On line 23

Something is wrong with the php code that should get all the images files and put them in the array.

  • 写回答

1条回答 默认 最新

  • duanhao4156 2014-11-02 19:56
    关注

    You can not use opendir to browse files over http. Instead you should try ftp connection, like:

    $username = 'ftp-username';
    $password = 'ftp-password';
    $basepath = 'domains/newsxpressmedia.com/public_html/';
    $handle = opendir("ftp://{$username}:{$password}@ftp.ipage.com/{$basepath}files/radar-simulation-files")
    
    评论

报告相同问题?

悬赏问题

  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答