Archive for the 'apache' Category

Apache logs are not rotated in cpanel

Wednesday, November 21st, 2007

use this code to rotate the apache logs in /etc/httpd/logs/ The logs in /etc/httpd/domlogs are rotated according to setting in WHM -> Tweak settings

CODE:
  1. /etc/httpd/logs/*log {
  2. missingok
  3. notifempty
  4. sharedscripts
  5. compress
  6. postrotate
  7. /bin/kill -HUP `cat /usr/local/apache/logs/httpd.pid 2>/dev/null` 2> /dev/null || true
  8. endscript
  9. }

Force apache to download an image instead of opening it

Wednesday, February 21st, 2007

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"