Get the stream content file from remote files - php

I'm using phpseclib to connect to SFTP from PHP.
I need to get a zip files from the SFTP Server. Those zip files contains xml and jpg files. I should extract data from xml and stream from jpg files and then save all in the database. I can't download the zip file because I haven't write permissions.
Can I get the stream content file (zip, xml and jpg) from remote files? Note that I'm using phpseclib.

You can get the stream content, however for the ZIP you need to program yourself a library that operates on the stream for the ZIP format (I do not know which one of the existing libraries can that out of the box, the ones I know can't, perhaps pclzip).
Then you need to operate on in-memory streams from the ZIP for the XML and JPG files which again needs to use stream compatible libraries - most likely you will need them to write yourself in context of PHP. Or at least invest a fair amount of time to deal this way.
But yes, it's perfectly possible. And (hopefully) you can do it.

Related

Unzip a file in S3 using a stream

We have a zip file containing a large JSON file in it that we need to unzip. We currently fetch the file in a lambda using Laravel, copy and unzip it locally (in the lambda), and then upload the JSON file back to S3 for processing.
It however seems that the lambda doesn't process large files (moving it back to s3 after unzipping in the lambda). (180MB). We could continue to up the lambda resources (deployed via Laravel Vapor), however, we're looking for an in-memory option that could perhaps provide a streaming way of unzipping.
Is there such a solution for PHP?

Azure PHP SDK: download container's all blob in a single zip file

I want to download all blob from specified container as a zip file.
Is there any way to download its as zip directly from Azure, no need to process it on my server?
Currently I think like below:
file_put_contents("file_name", get_file_contents($blob_url));
I will store all files on my server and then create zip file of those and then will force to download. .
Azure has no such facility to generate a zip file for a bundle of blobs for you. Azure Storage is just... storage. You'll need to download each of your blobs via php sdk (or directly via api if you so choose).
And if you want the content zip'd, you'll need to zip the content prior to storing in blob storage.
Your code (in your question) won't work as-is, since get_file_contents() expects to work with file I/O, and that's not how to interact with blobs. Rather, you'd do something like this:
$getBlobResult = $blobClient->getBlob("<containername>", "<blobname>");
file_put_contents("<localfilename>", $getBlobResult->getContentStream());

Is there an Apache equivalent of nginx mod_zip?

I have been working a web app where I need to allow the user to select a number of files and allow them to download said files as a zip file. I am working with lots of data so storing the zip file in memory or on disk isn't an option.
I am currently using Apache and haven't been able to find any solutions to be able to dynamically create and stream zip files to a client. One thing I did find was nginx mod_zip that seems to do exactly what I want.
What would be an Apache equivalent to mod_zip, or another solution to dynamically zip and stream zip files (without using disk space or loading the whole file in memory)?

How to convert .caf file to .mp3 file using php?

I have created one webservice using php which upload audio file from IOS device to server.audio file gets uploaded as .caf format which is not supported by server so is there any way to convert .caf file to .mp3 or .wav file?
I want to create PHP script which will convert .caf file to .mp3 file any idea about it?
Thanks
Core Audio Format (.caf) is a audio file container developed by Apple for audio files. A .caf file can contains different audio file formats just like .mov container for different video formats.
So, changing the format from .CAF to .MP3 through Program is a difficult task but not impossible thing. I think you can use FFMPEG to change the format from CAF to MP3, just download the latest build or create your own are use the following command:
FFMPEG -i song.caf song.mp3
I haven't tried thing thing at all but think it will work. There is also a Perl Script available known as PACPL through which can be done as:
shell_exec("pacpl input.caf -to mp3");
You may or may not need to reconfigure the permissions or use sudo in there depending on the host server config.
.caf is just a container format, what's inside can vary, although the vast majority of the time it's going to be PCM uncompressed audio. This could actually be what was tripping Audacity and other programs up, as they were expecting PCM and what is inside the .caf is something else, like AAC. I've seen something similar happen with WAV files (which is also a container format, but has PCM audio in it most of the time).

Does GXml work with KMZ files?

Can Google Map API GXml parse .kmz files directly? if not how is the best way to convert .kmz file to .kml? The .kmz file is stored on database and PHP code is used to retrieve it.
I'm pretty sure that there's no way to unpack zipped data with Javascript, which you'd have to do before passing the data to GXml.parse.
GGeoXml can handle KMZ files. It does it by passing the URL to a Google server which unzips the data and parses it there, then returns the individual overlay objects to the Javascript client.
Since you're reading the data with PHP, you might consider unzipping it in your PHP script, and serving the unzipped data to the client. You may need to do some work to your PHP configuration in order to enable the PHP Zip File functions.

Categories