Файл: adultscript-2.0.3-pro/files/templates/defboot/extend/ajax/photo_album_upload.plugin.php
Строк: 71
<?php
defined('_VALID') or die('Restricted Access!');
function ajax_plugin_photo_album_upload()
{
$data = array('error' => '', 'message' => '', 'status' => 0);
if (isset($_GET['id'])) {
$unique_id = VF::factory('filter')->get('id', 'STRING', 'GET');
if (!ctype_digit($unique_id)) {
$data['error'] = 100;
$data['msg'] = 'Invalid unique identifier!';
return json_encode($data);
}
if (empty($_FILES) or !isset($_FILES['file'])) {
$data['error'] = 101;
$data['msg'] = 'No file was uploaded!';
return json_encode($data);
}
if ($_FILES['file']['error']) {
$data['error'] = 102;
$data['msg'] = $_FILES['file']['error'];
return json_encode($data);
}
set_time_limit(2*3600);
$filename = VFile::safe($_FILES['file']['name']);
$ext = VFile::ext($filename);
if (!in_array($ext, VCfg::get('photo.photo_allowed_ext'))) {
$data['error'] = 103;
$data['msg'] = 'Invalid extension! Allowed extensions: '.implode(', ', VCfg::get('photo.photo_allowed_ext')).'.';
return json_encode($data);
}
if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
$data['error'] = 104;
$data['msg'] = 'File is not a valid uploaded file!';
return json_encode($data);
}
if (filesize($_FILES['file']['tmp_name']) > (VCfg::get('photo.photo_max_size')*1024*1024)) {
$data['error'] = 107;
$data['msg'] = 'File exceeds the maximum allowed filesize of '.VCfg::get('photo.photo_max_size').' MB!';
return json_encode($data);
}
$secret = substr(md5(VF::cfg_item('secret')), -5);
$random = mt_rand();
$dst = TMP_DIR.'/uploads/'.$unique_id.'_'.$secret.'_'.$random.'.'.$ext;
if (!move_uploaded_file($_FILES['file']['tmp_name'], $dst)) {
$data['error'] = 105;
$data['msg'] = 'Failed to move uploaded file!';
return json_encode($data);
}
$info_file = TMP_DIR.'/uploads/'.$unique_id.'_'.$secret;
$data_line = serialize(array(
'file' => $unique_id.'_'.$secret.'_'.$random.'.'.$ext,
'filename' => $filename,
'ext' => $ext
));
if (!file_put_contents($info_file, $data_line."n", FILE_APPEND)) {
$data['error'] = 106;
$data['msg'] = 'Failed to write data file!';
return json_encode($data);
}
$data['status'] = 1;
return json_encode($data);
} else {
$data['error'] = 110;
$data['msg'] = 'No unique identifier set!';
return json_encode($data);
}
}