<small id='enXT6'></small><noframes id='enXT6'>

        <tfoot id='enXT6'></tfoot>
          <bdo id='enXT6'></bdo><ul id='enXT6'></ul>

        <legend id='enXT6'><style id='enXT6'><dir id='enXT6'><q id='enXT6'></q></dir></style></legend>
        <i id='enXT6'><tr id='enXT6'><dt id='enXT6'><q id='enXT6'><span id='enXT6'><b id='enXT6'><form id='enXT6'><ins id='enXT6'></ins><ul id='enXT6'></ul><sub id='enXT6'></sub></form><legend id='enXT6'></legend><bdo id='enXT6'><pre id='enXT6'><center id='enXT6'></center></pre></bdo></b><th id='enXT6'></th></span></q></dt></tr></i><div id='enXT6'><tfoot id='enXT6'></tfoot><dl id='enXT6'><fieldset id='enXT6'></fieldset></dl></div>

        字符串到 php 中的压缩流

        时间:2023-10-15
      1. <tfoot id='ImnZ8'></tfoot>
          <tbody id='ImnZ8'></tbody>

                <bdo id='ImnZ8'></bdo><ul id='ImnZ8'></ul>
                <i id='ImnZ8'><tr id='ImnZ8'><dt id='ImnZ8'><q id='ImnZ8'><span id='ImnZ8'><b id='ImnZ8'><form id='ImnZ8'><ins id='ImnZ8'></ins><ul id='ImnZ8'></ul><sub id='ImnZ8'></sub></form><legend id='ImnZ8'></legend><bdo id='ImnZ8'><pre id='ImnZ8'><center id='ImnZ8'></center></pre></bdo></b><th id='ImnZ8'></th></span></q></dt></tr></i><div id='ImnZ8'><tfoot id='ImnZ8'></tfoot><dl id='ImnZ8'><fieldset id='ImnZ8'></fieldset></dl></div>

              • <legend id='ImnZ8'><style id='ImnZ8'><dir id='ImnZ8'><q id='ImnZ8'></q></dir></style></legend>

                  <small id='ImnZ8'></small><noframes id='ImnZ8'>

                • 本文介绍了字符串到 php 中的压缩流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个带有我的数据库的处理服务器和一个服务数据库,可以以较低的带宽成本提供文件.在处理服务器上,php 无法创建文件,因此在发送到另一台服务器进行下载之前,必须使用流完成所有操作和/或保留在内存中.几天前,我发现了使用 'php://memory' 的流抽象,我可以做类似

                  I have a processing server with my database and a serving database to serve up files with a low bandwidth cost. On the processing server, php is not able to create files so everything must be done with streams and/or stay in memory before being sent over to another server for download. A few days ago I found out about the stream abstraction with 'php://memory' and that I can do something like

                  $fp=fopen('php://memory','w+');
                  fwrite($fp,"Hello world");
                  fseek($fp,0,SEEK_SET);
                  
                  //make a ftp connection here with $conn_id
                  $upload = ftp_fput($conn_id,"targetpath/helloworld.txt",$fp,FTP_BINARY);
                  

                  在内存中制作文件,然后允许我将它通过 ftp 传输到我的其他服务器.这正是我想要的,除了我还想在发送数据之前压缩数据——最好只使用 php 的本机部分,如 ziparchive,而不是额外的自定义类来进行特殊的流操作.我知道我非常接近以下...

                  to make the file in memory and then allow me to ftp it over to my other server. This is exactly what I want, except I also want to zip the data before sending it -- preferably using only native parts of php like ziparchive and not additional custom classes for special stream manipulation. I know that I am very close with the following...

                  $zip = new ZipArchive();
                  if($zip->open('php://memory', ZIPARCHIVE::CREATE)) {
                    $zip->addFromString('testtext.txt','Hello World!');
                    $fp = $zip->getStream('test'); if(!$fp) print "no filepointer";
                  
                    //make a ftp connection here with $conn_id
                    $upload = ftp_fput($conn_id,"targetpath/helloworld.zip",$fp,FTP_BINARY);
                  } else print "couldn't open a zip like that";
                  

                  失败的点是对 getStream 的调用(尽管我认为我使用正确,但它总是返回 false).看起来 zip 可以在php://memory"中制作文件,但由于某种原因 getStream 仍然失败,尽管我可能不太了解 ZipArchive 如何制作 zip...

                  The point at which this fails is the call to getStream (which always returns false although I think I am using correctly). It appears that the zip is fine making the file in 'php://memory' but for some reason getStream still fails although perhaps I don't sufficiently understand how ZipArchive makes zips...

                  我怎样才能从字符串到压缩文件指针,以便我可以通过 ftp 将 zip 文件传送到我的其他服务器?请记住,我无法制作任何文件,否则我只会制作 zip 文件,然后通过 ftp 将其复制.

                  How can I go from the string to the zipped filepointer so that I can ftp the zip over to my other server? Remember I can't make any files or else I would just make the zip file then ftp it over.

                  根据下面瘦子的建议,我尝试了以下操作

                  based on skinnynerd's suggestions below I tried the following

                  $zip = new ZipArchive();
                  if($zip->open('php://memory', ZIPARCHIVE::CREATE)) {
                    $zip->addFromString('testtext.txt','Hello World!');
                    $zip->close(); 
                  
                    $fp = fopen('php://memory','r+');
                    fseek($fp,0,SEEK_SET);
                  
                    //connect to ftp
                    $upload = ftp_fput($conn_id,"upload/transfer/helloworld.zip",$fp,FTP_BINARY);
                  }
                  

                  这确实制作了一个 zip 并将其发送过来,但 zip 是 0 字节大,所以我不认为 'php://memory' 像我想的那样工作......它实际上在关闭步骤中失败了——$zip->close() 返回 false,这让我想知道我是否可以将 zips 打开到 'php://memory' 中.有谁知道我可以按照这些方法尝试获取 zip 文件吗?

                  This does make a zip and send it over but the zip is 0 bytes large so I don't think that 'php://memory' works the way I thought... it actually fails at the close step -- the $zip->close() returns false which makes me wonder if I can open zips into 'php://memory' at all. Does anyone know what I can try along these line to get the zip?

                  推荐答案

                  它必须是 Zip 存档吗?由于您正在尝试节省带宽,因此它也可能是 gzip.

                  Does it have to be a Zip archive? Since you're trying to save bandwith it could be a gzip too.

                  <?php
                   $ftp_credentials = "ftp://USER:PASSWORD@HOST/helloworld.gz";
                   $gz = gzencode("Hello World!", 9);
                   $options = array('ftp' => array('overwrite' => true));
                   $stream_context = stream_context_create($options);
                   file_put_contents($ftp_credentials, $gz, 0, $stream_context);
                  ?>
                  

                  这篇关于字符串到 php 中的压缩流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 PHP 中通过 HTTP PUT 发送文件 下一篇:joomla sql 查询

                  相关文章

                • <legend id='0KGEi'><style id='0KGEi'><dir id='0KGEi'><q id='0KGEi'></q></dir></style></legend>
                • <i id='0KGEi'><tr id='0KGEi'><dt id='0KGEi'><q id='0KGEi'><span id='0KGEi'><b id='0KGEi'><form id='0KGEi'><ins id='0KGEi'></ins><ul id='0KGEi'></ul><sub id='0KGEi'></sub></form><legend id='0KGEi'></legend><bdo id='0KGEi'><pre id='0KGEi'><center id='0KGEi'></center></pre></bdo></b><th id='0KGEi'></th></span></q></dt></tr></i><div id='0KGEi'><tfoot id='0KGEi'></tfoot><dl id='0KGEi'><fieldset id='0KGEi'></fieldset></dl></div>

                  • <bdo id='0KGEi'></bdo><ul id='0KGEi'></ul>

                    <small id='0KGEi'></small><noframes id='0KGEi'>

                  1. <tfoot id='0KGEi'></tfoot>