This repository has been archived by the owner on May 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphoto.php
197 lines (158 loc) · 6.06 KB
/
photo.php
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/*
This file is a part of DAlbum. Copyright (c) 2003 Alexei Shamov, DeltaX Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if (!defined("DALBUM_ROOT"))
define("DALBUM_ROOT",".");
if (!defined("DALBUM_BROWSERROOT"))
define("DALBUM_BROWSERROOT","");
define("DALBUM_PHOTO_PAGE","1");
require_once(DALBUM_ROOT."/include/md5crypt.php");
require_once(DALBUM_ROOT."/include/functions.php");
require_once(file_exists(DALBUM_ROOT."/config/config.php")?DALBUM_ROOT."/config/config.php":DALBUM_ROOT."/include/config.php");
require_once(DALBUM_ROOT."/include/conffix.php");
require_once(DALBUM_ROOT."/include/album.php");
// Include custom functions
if (file_exists(DALBUM_ROOT."/config/custom.php"))
include_once(DALBUM_ROOT."/config/custom.php");
elseif (file_exists(DALBUM_ROOT."/include/custom.php"))
include_once(DALBUM_ROOT."/include/custom.php");
$sUserName=StartSessionAndGetUserName('private_no_expire');
if (function_exists('everypageCallback'))
everypageCallback($sUserName);
global $g_sResizedPrefix;
global $g_sThumbnailPrefix;
global $g_sThumbnailPath;
global $g_sResizedPath;
$sFile=@$_GET['file'];
if (!$sFile)
$sFile=@$_SERVER['ORIG_PATH_INFO'];
if (!$sFile)
$sFile= @$_SERVER['PATH_INFO'];
$image=&createImage();
$image->Init($sFile);
if ($sFile=="" || !$image->IsImageFilename())
{
hdr("404 Not found");
return;
}
if (!$image->SkipAccessCheck() )
{
// Create tree
$alb=&CAlbum::CreateFromArchive();
$alb->SetAccess($sUserName);
// find original file name
$sFolder=dirname_ex($sFile);
$sBase=basename($sFile);
$lastSub=basename($sFolder);
$bOriginalAccessCheck=false;
global $g_bShowOriginalImageButton;
if ($g_sThumbnailPath==$lastSub)
{
$sBase=substr($sBase,strlen($g_sThumbnailPrefix));
$sFolder=dirname_ex($sFolder);
}
else if ($g_sResizedPath==$lastSub)
{
$sBase=substr($sBase,strlen($g_sResizedPrefix));
$sFolder=dirname_ex($sFolder);
}
else if (!$g_bShowOriginalImageButton)
{
// There could be an attempt to download an original image while access to the original
// images has been disabled.
$bOriginalAccessCheck=true;
}
$s=$sFolder . '/'. $sBase;
// Find album
$album=&$alb->FindAlbum($sFolder);
if (empty($album))
{
hdr("404 Not found");
return;
}
if ($album->m_bPrivate)
{
dalbum_relocate("login.php?url=" . encodeCurrentLocation());
return;
}
if ($bOriginalAccessCheck)
{
$album->LoadImages();
$album->LoadDetails();
global $g_sResizedXSize,$g_sResizedYSize;
for ($i=0;$i<count($album->m_arrContents);++$i)
{
if ($album->m_arrContents[$i]->IsImage() &&
$album->m_arrContents[$i]->m_sBaseFilename==basename(strval($sFile)))
{
$n=$i;
$image=&$album->m_arrContents[$i];
$image->CreateThumbnail(false,false);
$bResize=$image->m_bResize;
if ($image->m_bResize &&
($image->m_nX>$g_sResizedXSize || $image->m_nY>$g_sResizedYSize) &&
file_exists(absfname($image->GetResizedFilename())))
{
// There is a resized image, original cannot be served
hdr("404 Not found");
return;
}
}
}
}
}
$sFile=absfname($image->m_sFullFilename);
if (!file_exists($sFile))
{
hdr("404 Not found");
return;
}
$cache_time=@filemtime($sFile);
$requested_time=0;
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
$requested_time=@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
header("Last-Modified: " . gmdate("D, d M Y H:i:s",$cache_time) . " GMT");
// If server time zone is set incorrectly, it may prevent images from caching
// Thus we say that the page is not modified if time difference is less that
// one day and number of minutes and seconds is equal
// Also image caching is broken in Google Chrome
if( @abs($cache_time-$requested_time)<86400 && ($cache_time%3600)==($requested_time%3600))
{
if (!isset($_SERVER['HTTP_USER_AGENT']) || strstr($_SERVER['HTTP_USER_AGENT'],'AppleWebKit/')===FALSE)
{
hdr("304 Not Modified");
return;
}
}
$contentType=$image->GetImageMimeType();
if (isset($_GET['download']))
$contentType="application/octet-stream";
$size=filesize($sFile);
header("Content-type: $contentType");
header('Content-Disposition: inline; filename="' . $image->m_sBaseFilename . '"');
header("Content-length: " . $size);
@set_time_limit(86400); // set long timeout
// readfile consumes too much memory :(
$handle=fopen($sFile,"rb");
while($handle && !feof($handle))
{
$buffer = fread($handle, 4096);
if (strlen($buffer) == 0)
break;
print $buffer;
}
if ($handle)
fclose($handle);
?>