phpzend-frameworkfile-uploadzend-http-client

How to use Zend_Http to send and receive files


My client code is:

$Client = new Zend_Http_Client(
        $url,
        array(
          'maxredirects' => 1,
          'timeout'      => 5,
          'useragent'    => 'LMS_LiveAccess'
        )
);
$Client->resetParameters();
$Client->setMethod(Zend_Http_Client::POST);
$Client->setFileUpload('/home/itaymoav/outer.xml','outer.xml');
$Client->request();

On my server, when I do var_dump($_FILES) I do see the file name and the correct size.

outer_xml = Array
(
name = outer.xml
type = text/plain
tmp_name = /home/itaymoav/files/phpecWKHK
error = 0
size = 1752
)

But when I go to the temp folder (where the $_FILES tells me it saved the file) it is empty. I both tried the tmp folder and a different folder with chmod 777. nothing.
What am I missing?


Solution

  • To save the uploaded file, you must move them to another location, like this.

      move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
    

    From the manual, it says,

    The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.

    Here is an simple example.