Skip to content
Advertisement

Is there a way to stream a remote file as “zipped” without downloading to server?

Look at this simple code

<?php
readfile('http://ovh.net/files/1Mio.dat');
?>

This code together with the link are examples.

My server is working as if it were a kind of proxy. Displaying a remote raw file for the user.

I cannot download the file to my server because it is too big. I can’t save to the server, I can’t do anything with the file itself.

I need and searched the internet all about file formats (zip, rar, tar, gzip etc) that had the raw code of the archiver as simple as I could display to the user something like.

echo "#filename,filesize";
readfile ($url1);
echo "#filename1,filesize1";
readfile ($url2);

So user gets a raw file like this

#file1.dat,12312
(rawdata of file)
#file2.dat,1232
(rawdata of file)

And the final file, it would be like a zip file containing these 2 files

I tried a lot however I didn’t get any satisfactory answer.

All the answers I find are necessary to download the file on the server.

It also doesn’t really have to be zip, any other usable format. One option would be to simply display all of the entire files and leave it to the user to split it up into pieces with some file splitter, but that is not a friendly thing either.

@edit cant load into memory aswell

Advertisement

Answer

I managed to achieve exactly what I wanted. It is not very pretty but it just works most of times

I can easily open the file in 7zip-manager, view and extract the files. Its Unix Archiver (a file) https://en.wikipedia.org/wiki/Ar_(Unix)

<?php
echo "!<arch>n";
echo "file1.mp4/      1618101072  0     0     100644  1570024   `n";
readfile("https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4");
echo "file2.mp4/      1618101072  0     0     100644  1570024   `n";
readfile("https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4");
?>

most of times:

Unfortunately, at least using this example, some files just don’t work.

Maybe it’s something related to the character at the end or beginning of the file, I don’t know. I’m investigating

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement