PHP gets file as byte array using Zend_Form
We use Zend_Form inside a PHP application to create an input file html element. We can set the "destination" of this element, and when we call the receive () method, the file will be saved in the specified location.
We want to be able to not save the file to disk at all, but grab the file as a byte array and do something else with it.
Is it possible? If this is not possible with Zend_Form (), can it be done in any other way?
EDIT: The reason we can't write to disk is because the app is running on Azure and it doesn't seem to have write permissions anywhere, not even the temp folder. We get an exception from Zend saying "this destination could not be written."
source to share
The files will be stored on the default temporary server by default, unless a different location has been provided using
Instead of using it
to handle the download, try accessing it directly using an array
, which will allow you to read the file in line using file_get_contents () or similar functions. However, you can use
to create and manipulate the form in general.
You can configure shared memory
to map the file system to memory where downloaded files are stored. Be careful with this, as if someone is trying to download a very large file, it will end up in memory, which can affect performance or maintenance cost.
calls move_uploaded_file () to move the file from its temporary location to a permanent location. Also, it makes sure the download is valid and filters it and marks it as received so it can't be moved again (since it didn't work).
source to share