Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8238061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:41:07+00:00 2026-06-07T19:41:07+00:00

I have a processing server with my database and a serving database to serve

  • 0

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);

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";

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…

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.

EDIT: 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);
}

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:41:09+00:00Added an answer on June 7, 2026 at 7:41 pm

    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);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application running on a Windows Server 2008, that is processing uploaded
Hey. I use delayed_job for background processing. I have 8 CPU server, MySQL and
I currently have a SQL Server 2005 database that is accessed by multiple users.
I have to import a log file to SQL Server Database. File size is
(Advantage Database Server) I have a table of service providers that, for auditing purposes,
I have a SQL Server 2008 database with approximately 14 millions rows. In it
I have been investigating some performance issues with my database (SQL Server 2008). SQL
I have a C# console application, which interacts with a SQL Server Database, and
I have a jQuery DataTable configured for server-side processing against an ASP.NET MVC server.
I have a Sinatra server that is returning multiple JSON objects from the database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.