php自动创建ftp服务器地址,php – 创建zip存档并将其流式传输到ftp服务器

我试图从本地文件创建一个zip文件,并将其直接流式传输到ftp(不先将zip写入磁盘).我没有拉链本身的问题,但似乎ZipArchive类无法识别ftp流包装器.

以下代码是我能想出的最简单的事情,它将说明问题

$zip = new ZipArchive();

var_dump($zip->open('ftp://[username]:[password]@[hostname.net]/public_html/test.zip', ZipArchive::OVERWRITE));

$zip->addFile(realpath('/input.txt'), 'input.txt');

var_dump($zip->close());

$zip-> open调用返回true,而$zip-> close返回false.我找不到一种方法来获取错误消息或某些更具体的内容,而不仅仅是出现错误.问题是我做错了什么,或者我不能用ZipArchive类做这些事情.

解决方法:

我已经在我的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.

标签:php,stream,zip,ftp,ziparchive

来源: https://codeday.me/bug/20190620/1248092.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值