我已经在我的Ubuntu系统上测试了你的代码,我可以确认它不起作用.
通过使用“strace”实用程序,我已经看到PHP正在处理“$filename”参数,就像它是本地文件名一样,如下所示:
lstat64("/var/www/test/ftp://myuser:mypass@127.0.0.1/tmp/test.zip", 0xbfcbb008) = -1 ENOENT (No such file or directory)
lstat64("/var/www/test/ftp://myuser:mypass@127.0.0.1/tmp", 0xbfcbaeb8) = -1 ENOENT (No such file or directory)
lstat64("/var/www/test/ftp://myuser:mypass@127.0.0.1", 0xbfcbad68) = -1 ENOENT (No such file or directory)
lstat64("/var/www/test/ftp:", 0xbfcbac28) = -1 ENOENT (No such file or directory)
“/ var / www / test”前缀是我的PHP测试脚本的路径.
因此,似乎有效的ZipArchive :: open()方法无法处理URL文件名.
看一下PHP源代码,我发现ZipArchive :: open()方法调用了“zip_open”函数.
“fopen”函数的PHP手册页指出:
If filename is of the form “scheme://…”, it is assumed to be a URL
and PHP will search for a protocol handler (also known as a wrapper)
for that scheme. If no wrappers for that protocol are registered, PHP
will emit a notice to help you track potential problems in your script
and then continue as though filename specifies a regular file.
This post,在PHP手册页中找到“stream_wrapper_register”函数,声明zip_open()忽略自定义流包装器,但上面的测试表明它也忽略了标准流包装器.
同样,ZipArchive::open() manual page和zip_open手册页都明确表示“$filename”参数可以是URL.