File: view_jpeg_photo.php

package info (click to toggle)
phpldapadmin 1.1.0.5-6%2Blenny2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,008 kB
  • ctags: 3,949
  • sloc: php: 17,735; xml: 1,532; sh: 388; makefile: 46
file content (37 lines) | stat: -rw-r--r-- 1,227 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/view_jpeg_photo.php,v 1.11.2.1 2007/12/26 09:26:32 wurley Exp $

/**
 * @package phpLDAPadmin
 */
/**
 */

require './common.php';

$file['name'] = get_request('file','GET');

/* Security check (we don't want anyone tryting to get at /etc/passwd or something)
 * Slashes and dots are not permitted in these names.
 */
if (! preg_match('/^pla/',$file['name']) || preg_match('/[\.\/\\\\]/',$file['name']))
	pla_error(sprintf('%s: %s',_('Unsafe file name'),htmlspecialchars($file['name'])));

/* Little security measure here (prevents users from accessing
   files, like /etc/passwd for example).*/
$file['name'] = basename(addcslashes($file['name'],'/\\'));
$file['name'] = sprintf('%s/%s',$_SESSION[APPCONFIG]->GetValue('jpeg','tmpdir'),$file['name']);
if (! file_exists($file['name']))
	pla_error(sprintf('%s%s %s',_('No such file'),_(':'),htmlspecialchars($file['name'])));

$file['handle'] = fopen($file['name'],'r');
$file['data'] = fread($file['handle'],filesize($file['name']));
fclose($file['handle']);

if (ob_get_level())
	ob_clean();

Header('Content-type: image/jpeg');
Header('Content-disposition: inline; filename=jpeg_photo.jpg');
echo $file['data'];
?>