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

  • SEARCH
  • Home
  • 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 8476125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:05:36+00:00 2026-06-10T18:05:36+00:00

I am trying to create a zip file from local files and stream it

  • 0

I am trying to create a zip file from local files and stream it directly to an ftp (without writing the zip to disk first). I have no problems with zipping itself but it seems like the ZipArchive class doesn’t recognize the ftp stream wrapper.

The following code is the simplest thing I could come up with that will illustrate the problem

<?php

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

The $zip->open call returns true while $zip->close returns false. I can’t find a way to get an error message or something that can be more specific than just there is an error. The question is what am I doing wrong, or I can’t do these kind of stuff with the ZipArchive class.

  • 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-10T18:05:38+00:00Added an answer on June 10, 2026 at 6:05 pm

    I’ve tested your code on my Ubuntu system and I can confirm that it does’nt work.
    By using the “strace” utility, I’ve seen that the PHP is handling the “$filename” argument as if it was a local file name, as you can see below:

    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)
    

    The “/var/www/test” prefix is the path of my PHP test script.
    So, it seems that effectively the ZipArchive::open() method cannot handle URL filenames.
    Looking at the PHP source code, and I’ve discovered that the ZipArchive::open() method calls the “zip_open” function.
    The PHP manual page for the “fopen” function states:

    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, found in the PHP manual page for the “stream_wrapper_register” function, states that zip_open() ignores custom stream wrappers, but the above test shows that it also ignores standard stream wrappers.
    It’s also true that neither ZipArchive::open() manual page nor the zip_open manual page explicitly say that the “$filename” parameter can be a URL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a zip file from post attachments in wordpress .
I'm trying to use Node.js to create a zip file from an existing folder,
I'm trying to create a zip file from file contents which are being piped
I'm trying to use the following code to create a zip file from a
I'm trying to create a zip file from a directory in Java, then place
I'm trying to create a .zip file from an asset from another server like
I'm trying to create a Zip file from .Net that can be read from
I am trying to create a zip file in PHP. The server environment is
I am trying to create a zip file and want to preserve most of
I am trying to read a single file from a java.util.zip.ZipInputStream , and copy

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.