What’s the problem of Zend Framework’s file upload approach? As I couldn’t make it work it appears it really isn’t possible to make it work.
Can anyone tell me how to manage this abstraction over the PHP upload process work?
What’s the problem of Zend Framework’s file upload approach? As I couldn’t make it work it appears it really isn’t possible to make it work.
Can anyone tell me how to manage this abstraction over the PHP upload process work?
It may sound strange, because all this is quite well documented in the Zend Framework documentation. Indeed it’s very very simple and all is done only by few lines of code.
$mail = new Zend_Mail(); $mail->setFrom('sender@example.com'); $mail->setBodyHtml('some message - it may be html formatted text'); $mail->addTo('recipient@example.com', 'recipient'); $mail->setSubject('subject'); $mail->send(); |
Even it look simple though, it may not work on your localhost while you’re trying to make it work! Because you’ve to have sendmail setup. And in Zend Framework sendmail is the default transport protocol for sending mails.
Actually you’ve simply to add a transport protocol, just like that:
$tr = new Zend_Mail_Transport_Smtp('smtp.example.com', array('auth' => 'login', 'username' => 'username', 'password' => 'password')); Zend_Mail::setDefaultTransport($tr); |
Well look at your favorite mail account you probably use every day. It may be hosted in GMail or wherever, but there are some configurations you have to port under Zend’s code and everything will be just fine until you develop the app!
You’ve probably seen that you can track the server response headers with Firebug – a wonderful extension to Firefox.
But have you ever asked yourself how to change a response header with Zend Framework.
Typically this is done with the built in PHP function header, where you can setup the header the page must return, but how to make it with Zend Framework?
It’s pretty simple of course, it’s Zend Framework in fact. To be more precise I’ll post a snippet:
$response = $this->getResponse(); $response->setHeader('content-type', 'application/x-javascript; charset=utf-8'); $response->sendResponse(); |
This is a common task. You’d like to know whether the image on the remote server exists. Zend Framework gives the answer of this question and in particular this can be completed with Zend_Http_Client.
The little problem is that checking for content-type is not always correct, because it will return an image content type even when the image does not exists, so it’s better to check for content-length.
The simple way to check this is like that:
$client = new Zend_Http_Client('http://remote-machine/image.jpg'); $response = $client->request('head'); if ( NULL == $response->getHeader('Content-Length') ) // do whatever if the image does not exists. |
In fact here, in this example I don’t check for GET request, because is way to slow than the HEAD method, but you should be aware of incorrect responses when using HEAD. In fact if you request the HEAD of a FLV video it will be returned text content-type, while using GET everything’s working fine but slow though.
Zend Framework gives you the possibility to interact with Gdata services, which are provided by most of the Goolge services. You can find more on the docs page of Zend_Gdata. The basic principle is that you can connect a service with you API key, given by Google. What I’m about to show you is how do connect such a service.
In theory Zend_Gdata depends on Zend_Http_Client and you’ve to connect it with an instance of this class.
// 1. setup API key $apiKey = 'your_api_key_here'; // 2. retrieve videos via GData Atom $client = new Zend_Http_Client(); $gdata = new Zend_Gdata_YouTube(null, 'my-app', null, $apiKey); |
Note that you’ve to replace your API key in the chunk above.
Now once that you’ve connected the YouTube service you can iterate through the entries from the video feed.
$videoFeed = $gdata->getUserUploads('username'); foreach ($videoFeed as $entry) { echo $entry->getTitle(); } |
The thing is that you can modify a bit the code above. As ZF docs says if you don’t setup a Zend_Http_Client a default with default configuration, so you can omit this and simple write:
// 1. setup API key $apiKey = 'your_api_key_here'; // 2. retrieve videos via GData Atom $gdata = new Zend_Gdata_YouTube(null, 'my-app', null, $apiKey); |