@@ -155,13 +155,16 @@ public static function getAutoClass($config)
155
155
*/
156
156
public static function getPath ($ skip_create_path = false , $ config )
157
157
{
158
- if (! isset ( $ config [ ' path ' ]) || $ config [ ' path ' ] == '' ) {
158
+ $ tmp_dir = ini_get ( ' upload_tmp_dir ' ) ? ini_get ( ' upload_tmp_dir ' ) : sys_get_temp_dir ();
159
159
160
+ if (!isset ($ config [ 'path ' ]) || $ config [ 'path ' ] == '' ) {
160
161
if (self ::isPHPModule ()) {
161
- $ tmp_dir = ini_get ('upload_tmp_dir ' ) ? ini_get ('upload_tmp_dir ' ) : sys_get_temp_dir ();
162
162
$ path = $ tmp_dir ;
163
163
} else {
164
- $ path = isset ($ _SERVER [ 'DOCUMENT_ROOT ' ]) ? rtrim ($ _SERVER [ 'DOCUMENT_ROOT ' ], '/ ' ) . '/../ ' : rtrim (__DIR__ , '/ ' ) . '/ ' ;
164
+ $ document_root_path = rtrim ($ _SERVER [ 'DOCUMENT_ROOT ' ], '/ ' ) . '/../ ' ;
165
+ $ path = isset ($ _SERVER [ 'DOCUMENT_ROOT ' ]) && is_writable ($ document_root_path )
166
+ ? $ document_root_path
167
+ : rtrim (__DIR__ , '/ ' ) . '/ ' ;
165
168
}
166
169
167
170
if (self ::$ config [ 'path ' ] != '' ) {
@@ -187,7 +190,7 @@ public static function getPath($skip_create_path = false, $config)
187
190
188
191
$ securityKey = self ::cleanFileName ($ securityKey );
189
192
190
- $ full_path = $ path . '/ ' . $ securityKey ;
193
+ $ full_path = rtrim ( $ path, ' / ' ) . '/ ' . $ securityKey ;
191
194
$ full_pathx = md5 ($ full_path );
192
195
193
196
@@ -200,6 +203,16 @@ public static function getPath($skip_create_path = false, $config)
200
203
if (!@is_writable ($ full_path )) {
201
204
@chmod ($ full_path , self ::__setChmodAuto ($ config ));
202
205
}
206
+ if (!@is_writable ($ full_path )) {
207
+ // switch back to tmp dir again if the path is not writeable
208
+ $ full_path = rtrim ($ tmp_dir ,'/ ' ) . '/ ' . $ securityKey ;
209
+ if (!@file_exists ($ full_path )) {
210
+ @mkdir ($ full_path , self ::__setChmodAuto ($ config ));
211
+ }
212
+ if (!@is_writable ($ full_path )) {
213
+ @chmod ($ full_path , self ::__setChmodAuto ($ config ));
214
+ }
215
+ }
203
216
if (!@file_exists ($ full_path ) || !@is_writable ($ full_path )) {
204
217
throw new phpFastCacheCoreException ('PLEASE CREATE OR CHMOD ' . $ full_path . ' - 0777 OR ANY WRITABLE PERMISSION! ' , 92 );
205
218
}
0 commit comments