开发者

Create a file in a zip archive using stream wrapper

开发者 https://www.devze.com 2022-12-11 14:57 出处:网络
I want to use a zip stream wrapper in PHP to create zip file or add files in a zip archive. Here are my example :

I want to use a zip stream wrapper in PHP to create zip file or add files in a zip archive. Here are my example :

<?php
echo file_get_contents('zip://file.zip#existing_file.txt');
file_put_contents('zip://file.zip#new_file.txt', 'Trying to put some stuff here...');
echo file_get_contents('zip://file.zip#new_file.txt');

This code gets me this output :

$ php test.php 
Hey, I'm an existing text in a file in a zip archive !

Warning: file_put_contents(zip://file.zip#new_file.txt): failed to open stream: operation failed in /home/sylvain/test.php on line 7

Warning: file_get_contents(zip://file.zip#new_file.txt): failed to open stream: operation failed in /home/sylvain/test.php on line 9

I get th开发者_运维百科e same error when the zip file just doesn't exist.

Here are the file permissions :

$ ls -la
total 24
drwxrwxrwx   2 sylvain sylvain  4096 2009-11-13 14:44 .
drwxr-xr-x 134 sylvain sylvain 12288 2009-11-13 14:44 ..
-rwxrwxrwx   1 sylvain sylvain   236 2009-11-13 14:44 file.zip
-rwxrwxrwx   1 sylvain sylvain   268 2009-11-13 14:44 test.php

Is it possible to do what I'm trying to do without creating a new stream wrapper ?


zip:// stream wrapper does not support writes: http://php.net/manual/en/wrappers.compression.php

Besides, Zip archives cannot be written in a stream because the CRC comes before the compressed data


Hey you tired to chmod your folder to 777 in which the ZIP file is in?

Edit: It looks as though your files are not 777 and your folder. I could be wrong, just woke up. chmod 777 the folder itself and let me know if that doesn't work.

0

精彩评论

暂无评论...
验证码 换一张
取 消