读取远程服务器文件,列出目录

时间:2012-09-19 15:41:56

标签: php function remote-server

我们正在努力重写这个照片库功能。它在与图像相同的服务器上完美地工作。现在,由于代价高昂的影响,我们不得不将所有图像移动到另一台服务器上。

图库功能在同一台服务器上运行良好。当我们尝试远程服务器路径时: http://www.myotherserver.com - 那就是它返回NO图像的地方?

我们发现“功能”在没有图像文件的情况下读取/列出图像,但是我们无法对其进行解码以在远程服务器上使用它?

任何帮助或想法?感谢。

这是功能:

请注意::我们不会使用带图像顺序的.txt文件 - 我们只希望脚本读取目录并列出要使用的图像..

/**
 * Check for image order file. In case it does not
 * exists, read the image directory.
 */
  if (is_file($order_file_path . '/' . $order_file_name)) {

  $fp  = fopen($order_file_path . '/' . $order_file_name, "r");
    $row = '';
    $use_order_file = 'true';

    while ($data = fgetcsv ($fp, 1000, ';')) {
        $image_data[] = trim($data[0]);
        $image_file_names[trim($data[0])] = trim($data[0]);
        $num = count($data);
        $row++;

        for ($j = 0; $j < $num; $j++) {
            $content_data_temp['field_' . $j] = $data[$j];
        } 

        $content_data[] = $content_data_temp;
        $content_data_temp = '';
    } 
    fclose ($fp);
} else if (is_dir($image_path)) {
    $content_data = '';
    $handle = opendir($image_path);

    while ($file = readdir($handle)) {
        if (preg_match("/^\.{1,2}$/i", $file)) {
            continue;
        } 
        if (preg_match("/\.[a-z]{3}$/i", $file)) {
            $image_data[] = $file;
            $image_file_names[$file] = $file;
        } 
    } 
    closedir($handle);
} else {
    echo 'Image Path not working';
    exit;
} 

$image_number = count ($image_data);

1 个答案:

答案 0 :(得分:1)

您可以查看的一个选项是将远程图片目录作为NFS共享进行安装。这样,您的脚本就可以正常工作,因为NFS共享就像本地目录一样。

除此之外,您必须记住,从一台服务器您无法访问其他服务器文件系统,因此该脚本将无法运行。我能想到的一个“脏”选项是在图片机中设置索引,导航到'文件夹'并解析生成的HTML。