函数glob()不能与externe URL一起工作 [英] Function glob() not working with externe URL

查看:175
本文介绍了函数glob()不能与externe URL一起工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在本地 strong 本地时,我对这个问题感到困惑
这就是所有罚款


foreach glob(public / FolderA / B /)为$ filename){

但是当我把

foreach(glob (http://www.exemple.com/public/FolderA/B/)为$ filename){


无法解决任何问题? ??


历史记录:过去,我正在使用glob()并与本地服务器进行通信,并且scripte完成了这项工作现在donne将传输到其他服务器,我得到的问题是如何将glob()工作与外部URL不在本地或某些功能具有相同的功能

i'm confused with this problem when im working locally it's all fine with this :
foreach (glob("public/FolderA/B/") as $filename) {
but when i put
foreach (glob("http://www.exemple.com/public/FolderA/B/") as $filename) {
doesn't work any solution ???
History : in the past i'm working with glob() and communicate with local server and the scripte do this jobs perfect now donne is transfert to other server and problem i get is how to put glob() working with external URL not locally or some function has same functionality

推荐答案

每个定义的glob()查找匹配模式的路径名。
这意味着函数在远程文件上不起作用,因为要检查的diretory /文件必须可以通过服务器的文件系统访问。

glob() per definition finds pathnames matching a pattern.
This means that the function will not work on remote files as the diretory / files to be examined must be accessible via the server's filesystem.

你可能需要的是通过一个远程文件系统访问 FTP 服务器。

What you probably would need is accessing a remote filesystem thru an FTP server.

这可能是这样的:

This is how it could look like:

$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
get contents of the current directory
$contents = ftp_nlist($conn_id, ".");  // "." means the current directory
var_dump($contents);

或者,如果以前的本地服务器仍然可以访问,则可以在此服务器扫描该目录与之前一样并且回显文件列表(例如,以XML或JSON格式)。这个脚本可以通过(now)远程脚本发送一个请求,以这种方式给出文件列表。

Alternatively, if the previously local server still can be accessed, you could have a script on this server scan the directory as before and echo the file list (e.g. in XML or JSON format). This script could the be sent a request by the (now) remote script, giving the file list this way.

<?php

$ftp_server   = 'ftp.example.org';
$ftp_port     = 21;
$ftp_timeout  = 90;
$ftp_user     = 'my_username';
$ftp_password = 'my_password';

// set up a connection or die
$conn_id = ftp_connect($ftp_server, $ftp_port, $ftp_timeout);
if ($conn_id===false) {
    echo 'Failed to connect to the server<br />';
    exit(1);
}

// Log in or die
$logged_in = ftp_login($conn_id, $ftp_user, $ftp_password);
if ($logged_in!==true) {
    echo 'Failed to log-in<br />';
    exit(1);
}

// Change directory if necessary
echo "Current directory: " . ftp_pwd($conn_id) . '<br />';

// Set to passive mode if required
ftp_pasv ($conn_id, true);

// Change directory if necessary
if (ftp_chdir($conn_id, 'subdir1/subdir2')) {
    echo "Current directory is now: " . ftp_pwd($conn_id) . '<br />';
} else {
    echo 'Could not change directory<br />';
    exit(1);
}

// Get list of files in this directory
$files = ftp_nlist($conn_id, ".");
if ($files===false) {
    echo 'Failed to get listing<br />';
    exit(1);
}

foreach($files as $n=>$file) {
    echo "$n: $file<br />";
    $local_dir = '/my_local_dir/';
    foreach($files as $n => $file) {
        // These we don't want to download
        if (($file=='.') || ($file=='..') || ($file[0]=='.')) continue;
        // These we do want to download
        echo "$n: $file<br />";
        if (ftp_get($conn_id, $local_dir.$file, $file, FTP_BINARY)) {
            echo "Successfully written to $local_dir$file<br />";
        } else {
            echo "Could not get $local_dir.$file<br />";
        }
    }
    // Do whatever has to been done with $file
}

?>

这篇关于函数glob()不能与externe URL一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆