We are using Zend_Form inside a PHP application for building an input file html element. We can set the ‘destination’ of this element, and when calling receive() the file will be saved to the specified location.
We want to be able not to save the file to disc at all, but grab the file as a byte array and do something else with it.
Is this possible? If it is not possible with Zend_Form(), can it be done any other way?
EDIT: The reason why we cannot write to disc is because the application runs on Azure, and it seems that it does not have write access rights anywhere, not even in the temp folder. We get an exception from Zend saying that ‘The given destination is not writeable’.
All PHP uploads are written to the file system regardless of using Zend or not (see upload_tmp_dir and POST method uploads).
Instead of using
receiveto process the upload, try accessing it directly using the$_FILESarray which would let you read the file into a string using file_get_contents() or similar functions. You can however, still useZend_Formto create and handle the form in general.You could set up shared memory
upload_tmp_dirto map a filesystem to memory where uploaded files are held. Be cautious with this as if someone attempts to upload a very large file, it will go into memory which could affect performance or your cost of service.Ultimately,
Zend_File_Transfer_Adapter_Http::receive()calls move_uploaded_file() to move the file from its temporary location to the permanent location. In addition it makes sure the upload is valid and filters it, and marks it as received so it cannot be moved again (as that would fail).