Skip to content


Force apache to download an image instead of opening it

Have you ever came across a situation where you wanted an image to download instead of having the browser to display it? This is how you can do it . Enter the following code in a php file foo.php and call it like foo.php?file=myimage.jpg. Then a browser save dialog box will appear.

PHP:
  1. if(!$_GET['file']){exit;}
  2. $file = basename($_GET['file']);
  3. header("Content-Length: " . filesize($file));
  4. header('Content-Type: image/jpg');
  5. header('Content-Disposition: attachment; filename='.$file);
  6. readfile($file);

If you want to do the same with other kind of files like video etc, just replace the 'image/jpg' above with on of the following:

"pdf": "application/pdf"
"exe": "application/octet-stream"
"zip": "application/zip"
"xls": "application/vnd.ms-excel"
"ppt": "application/vnd.ms-powerpoint"
"gif": "image/gif"
"png": "image/png"
"jpg": "image/jpg"
"mp3": "audio/mpeg"
"mp3": "audio/mp3"
"wav": "audio/x-wav"
"mpe": "video/mpeg"
"mov": "video/quicktime"
"avi": "video/x-msvideo"

Posted in apache, php.


CakePHP used for UN data sharing

BrainOff explains how he used the cakephp framework for building a simple application with CRUD administration and a Searchable front end. The application is used by the UN INSTRAW researchers.

Posted in cakephp, php.


I {heart} CakePHP

I {heart}CakePHP
View original post here.

Posted in cakephp.


Integrate CakePHP with Joomla!

There were times when I wanted to use Joomla! and integrate it with new functionalities. The best option would be to create new components for joomla, but I never got to do this, did not want to invest time in this. Now, that belongs to the past. I  just discovered this article by Max aka Abhimanyu Grover. He illustrates how to install joomla! within the cakephp framework and take all the advantages of cake while at the same time you get the user authentication and content management that joomla! offers. Great article, take a look.

Posted in Joomla!, cakephp, php.


CakePHP – Use recursive instead of unbind to unbind all associations

You can use recursive or unbind whenever you want to unbind associations from models. This is very useful because there are cases when you want to execute a simple query and you do not want to join other tables. Here comes unbind. Unbind allows us to unbind all but some model associations. On the other hand if you want to unbind all associations you can use recursive like this:

PHP:
  1. $this->Model->recursive = -1;

CakePHP is beautiful. I love it!

Posted in cakephp, php.