function upload() { $results = array(); $name = $_FILES['files']['name'][0]; $size = $_FILES['files']['size'][0]; $tmp_name = $_FILES['files']['tmp_name'][0]; // if (get_file_ext($name) != 'jpg' && get_file_ext($name) != 'jpeg' && get_file_ext($name) != 'png' && get_file_ext($name) != 'bmp') { $results['error'] = '对不起,系统只允许上传扩展名为 <strong>jpg/jpeg/png/bmp</strong> 的图片文件!'; $results['is_success'] = false; } else { if ($size > 2000000) { $results['error'] = '对不起,系统只允许上传小于 <strong>2M</strong> 的图片文件!'; $results['is_success'] = false; } else { // 上传成功! $upload_path = getcwd() . '/webroot/uploads/'; $md5_name = md5($name . date('Y-m-d H:i:s')) . '.' . get_file_ext($name); move_uploaded_file($tmp_name, $upload_path . $md5_name); // $results['is_success'] = true; $results['md5_name'] = $md5_name; } } return $results; }
protected function get_file_ext($filename) { if (defined('STRICT_TYPES') && CAMEL_CASE == '1') { return self::parameters(['filename' => DT::STRING])->call(__FUNCTION__)->with($filename)->returning(DT::VOID); } else { return get_file_ext($filename); } }
/** * $.ajax({ method: glob, dir: 'C:\htdocs\erp\nfe\received\', filter: '*.xml' }) * * return: files [ name: x...x , size: x...x , ext: xxx , time: yyyy-mm-dd hh:mm:ss ] http://erp/index.php/ajax?data={"method":"glob","select":"C:/htdocs/erp/nfe/received/","filter":"*.xml"} {"status":"ok" ,"files": [{"name":"42140176840701000109550010000512901007934549-nfe.xml" ,"ext":"xml","size": "7 KB","time":"2014-02-05 02:31:00"} ,{"name":"42140176840701000109550010000512911007906488-nfe.xml" ,"ext":"xml","size": "9 KB","time":"2014-02-05 02:31:00"} ,{"name":"42140182983404000107550020000733191000543240-procNFe.xml" ,"ext":"xml","size":"28 KB","time":"2014-02-05 02:29:00"} ,{"name":"42140182983404000107550020000733201000543259-procNFe.xml" ,"ext":"xml","size": "8 KB","time":"2014-02-05 02:30:00"} ,{"name":"42140182983404000107550020000733211000543264-procNFe.xml" ,"ext":"xml","size": "7 KB","time":"2014-02-05 02:30:00"} ,{"name":"42140182983404000107550020000733221000543270-procNFe.xml" ,"ext":"xml","size": "9 KB","time":"2014-02-05 02:31:00"} ,{"name":"42140876840701000109550010000582511008109044-nfe.xml" ,"ext":"xml","size": "8 KB","time":"2014-09-13 11:46:50"} ,{"name":"42140876840701000109550010000582521007990763-nfe.xml" ,"ext":"xml","size":"12 KB","time":"2014-09-13 11:45:23"} ]} */ function JKY_glob($data) { $my_files = array(); foreach (glob($data['select'] . $data['filter']) as $file_name) { $my_file = array(); $my_file['id'] = $file_name; $my_names = explode('/', $file_name); $my_file['name'] = $my_names[count($my_names) - 1]; $my_file['ext'] = get_file_ext($file_name); $my_file['size'] = put_size(filesize($file_name)); $my_file['time'] = date('Y-m-d h:i:s', filemtime($file_name)); array_push($my_files, $my_file); } $data = array(); $data['status'] = 'ok'; $data['rows'] = $my_files; return $data; }
/** Will return the plugin to use, based on the $http_post_uploadfile_r['name'] and/or the start of the file itself (available via: $http_post_uploadfile_r['tmp_name']) */ function &get_import_plugin_from_uploadfile($http_post_uploadfile_r, &$error) { $extension = strtolower(get_file_ext($http_post_uploadfile_r['name'])); if (strlen($extension) > 0) { if ($extension == 'xml') { // We need to find the DOCTYPE for the XML file, so we can assign an XML plugin. if (function_exists('xml_parser_create')) { if (file_exists($http_post_uploadfile_r['tmp_name'])) { $xmlParser = new DocTypeNameSpaceXMLParser(); if ($xmlParser->parseFile($http_post_uploadfile_r['tmp_name'])) { $docType = $xmlParser->getDocType(); $nameSpace = $xmlParser->getNameSpace(); unset($xmlParser); if (strlen($docType) > 0) { $importPlugin =& get_import_plugin_for_extension($extension, $docType, $nameSpace); if ($importPlugin !== NULL) { return $importPlugin; } else { $error = get_opendb_lang_var('doctype_not_supported', 'doctype', $docType); return NULL; } } else { $error = get_opendb_lang_var('no_doctype_found'); return NULL; } } else { $error = get_opendb_lang_var('file_upload_error'); return NULL; } } else { $error = get_opendb_lang_var('file_upload_error'); return NULL; } } else { $error = get_opendb_lang_var('xml_import_plugins_not_supported'); return NULL; } } else { $importPlugin =& get_import_plugin_for_extension($extension); if ($importPlugin !== NULL) { return $importPlugin; } else { $error = get_opendb_lang_var('extension_not_supported', 'extension', strtoupper($extension)); return NULL; } } } else { $error = get_opendb_lang_var('no_extension_found'); return NULL; } }
function fp_loadfile($Frm, $Err) { global $order_id; if (!$Err) { $f = $Frm->GetValue(0); //$f["tmp_name"] //$f["name"] //$f["size"] //$f["type"] if (is_uploaded_file($f["tmp_name"])) { $extension = get_file_ext($f['name']); if (trim($Frm->GetValueH(1)) == "") { $name = $f["name"]; } else { $name = trim($Frm->GetValueH(1)) . '.' . $extension; } $file_id = Order::attachFile($order_id, $_SESSION["user"]["data"]["id"], $name, $f["size"]); if (!$file_id) { $Frm->_gui->ERR("Ошибка при загрузке"); } else { $dir = DIR_FS_ORDER_FILES . $order_id . '/'; if (!is_dir(DIR_FS_ORDER_FILES)) { create_path('order_files', DIR_FS_DOCUMENT_ROOT); } if (!is_dir($dir)) { create_path($order_id, DIR_FS_ORDER_FILES); } $file_name = $file_id . '.' . $extension; if (move_uploaded_file($f['tmp_name'], $dir . $file_name)) { $Frm->_gui->OK("Файл загружен"); if ($_SESSION["user"]["data"]["group_id"] == 6 && get_order_author_id($order_id) == $_SESSION["user"]["data"]["id"]) { $res = change_order_status($order_id, 'RECEIVED_FILE_FROM_AUTHOR'); if ($res == 1) { $Frm->_gui->OK("Статус заказа изменен"); } else { $Frm->_gui->ERR($res); } } } else { Order::deleteAttachedFile($file_id); $Frm->_gui->ERR("Ошибка при сохранении файла"); } } page_reloadAll(); } } }
if (!unlink($entry)) { echo "##Error:file-" . $entry . " is not person"; } echo "<br />DELETE -file:" . $entry; continue; } } //这里判断是否删除目录 closedir($dh); if (rmdir($dir)) { echo "<br /><font color=red>" . $dir . "</font>"; $entry = $dir; } return true; } /** *获取文件的扩展名 */ function get_file_ext($filename) { $ext = pathinfo($filename); if (empty($ext['extension'])) { die('Unknow file extension!'); } return $ext['extension']; } $dir = "D:/www/OpenSource/frog"; $filename = $dir . '/index.chaozi'; delete_file($dir); echo get_file_ext($filename); //full_rmdir( $dir );
/** Will return the filename extension if it is legal. Or false otherwise. */ function get_valid_extension($filename, $extensions) { $ext = strtolower(get_file_ext($filename)); if ($ext !== FALSE) { // If no extension specified this indicates that all are legal. if (strlen($extensions) == 0) { return $ext; } else { // As $extensions is not empty, $extensions_r will have // at least one element. $extensions_r = explode(",", strtolower($extensions)); if (in_array($ext, $extensions_r)) { return $ext; } } } //else return FALSE; }
function SearchBuildings($name = "", $created_uid = "", $address = "", $bids = "", $province = "", $city = "", $district = "", $street = "", $btype = "", $pageSize = "", $page = "", $checkUserPoints = true, $includeUserPoints = false, $maxLng = '', $maxLat = '', $minLng = '', $minLat = '', $keywords = '') { $sql = "select b.*,u.uname from building b left join user u on b.create_uid=u.uid"; $order = " order by topic_count desc"; $where = " where 1=1"; $sqlcount = "select count(*) as rs from building b"; if ($page > 0) { if ($pageSize == "" || $pageSize == 0) { $pageSize = $this->Config['building_pagesize']; } $startrecord = $pageSize * ($page - 1); $endrecord = $pageSize * $page; $limit = ' limit ' . $startrecord . ',' . $pageSize; } if ($name != "" && (!$keywords || $keywords == "")) { //$where.=" and b.bname like '%$name%'"; $where .= " and b.bname ='{$name}'"; } if ($created_uid != "") { $where .= " and b.create_uid={$created_uid}"; } if ($address != "" && (!$keywords || $keywords == "")) { $where .= " and b.address like '%{$address}%'"; } if ($keywords && $keywords != "") { $where .= " and (b.bname like '%{$keywords}%' or b.address like '%{$keywords}%' or description like '%{$keywords}%')"; } if ($province != "" && $province != 0) { if (is_numeric($province)) { $where .= " and b.province='{$province}'"; } else { $where .= " and b.province in( select id from common_district where name='{$province}')"; } } if ($city != "" && $city != 0) { if (is_numeric($city)) { $where .= " and b.city='{$city}'"; } else { $where .= " and b.city in( select id from common_district where name='{$city}')"; } } if ($district != "") { $where .= " and b.district='{$district}'"; } if ($street != "") { $where .= " and b.street='{$street}'"; } if ($btype != '' && is_numeric($btype) && $btype > 0) { $where .= " and b.build_type_id={$btype}"; } if (isset($bids) && $bids != '') { if (!$includeUserPoints) { $where .= " and b.bid in({$bids})"; } else { $where .= " or b.bid in({$bids})"; } } if ($maxLng && $maxLng != '') { $where .= " and b.point_lng<='{$maxLng}'"; } if ($maxLat && $maxLat != '') { $where .= " and b.point_lat<='{$maxLat}'"; } if ($minLng && $minLng != '') { $where .= " and b.point_lng>='{$minLng}'"; } if ($minLat && $minLat != '') { $where .= " and b.point_lat>='{$minLat}'"; } $result = array(); $sqlcount = $sqlcount . $where . $order; $row = $this->DatabaseHandler->FetchFirst($sqlcount); if ($row != false) { $result['total'] = $row['rs']; } else { $result['total'] = 0; } $sqlr = trim($sql . $where . $order . $limit); $this->Logger->Write($sqlr); $query = $this->DatabaseHandler->Query($sqlr); $rows = $query->GetAll(); //do other things which related with points $uid = $this->User['uid']; $data = array(); foreach ($rows as $row) { $image = $row['face_url']; if ($image && $image != '') { $image_prefix = GetImagePrefix($image); } $image_profile_img = $image_prefix . "_p." . get_file_ext($image); if (file_exists($image_profile_img)) { $row['face_url_p'] = $image_profile_img; } else { $row['face_url_p'] = $row['face_url']; } $row['image_prefix'] = $image_profile_img; $bid = $row['bid']; if ($uid != "" && $checkUserPoints) { $fans = $this->DatabaseHandler->FetchFirst("select upid from userpoints where isfollowed=1 and uid={$uid} and building_id={$bid}"); if ($fans && count($fans) >= 1) { $row['fans'] = 1; } $ms = $this->DatabaseHandler->FetchFirst("select live_type from userpoints where changyong=1 and uid={$uid} and building_id={$bid}"); $row['home'] = 0; $row['work'] = 0; $row['school'] = 0; } if ($ms && count($ms) >= 1) { $row['member'] = 1; foreach ($ms as $m) { switch ($m['live_type']) { case "1": $row['home'] = 1; $row['work'] = 0; $row['school'] = 0; break; case "2": $row['home'] = 0; $row['work'] = 1; $row['school'] = 0; break; case "3": $row['home'] = 0; $row['work'] = 0; $row['school'] = 1; break; } } } $data[] = $row; } $result['data'] = $data; if ($result['total'] == 0) { $result['data'] = ''; } return $result; }
function import() { // 工装管理员 生产安全部 if (!has_perm(6, 1)) { exit; } $name = $_FILES['files']['name'][0]; $size = $_FILES['files']['size'][0]; $tmp_name = $_FILES['files']['tmp_name'][0]; if (get_file_ext($name) != 'xls') { $results['error'] = '对不起,系统只允许上传扩展名为 <strong>xls</strong> 的电子表格文件!'; $results['is_success'] = false; } else { if ($size > 2000000) { $results['error'] = '对不起,系统只允许上传小于 <strong>2M</strong> 的电子表格文件!'; $results['is_success'] = false; } else { if (!empty($tmp_name)) { $data = new \Spreadsheet_Excel_Reader(); $data->setOutputEncoding('UTF-8'); $cols = 12; /* 每一行有12个单元格 */ $data->read($tmp_name); error_reporting(E_ALL ^ E_NOTICE); // 对电子表格的每一行进行循环 // 检测到某个单元格不存在时,设定其为空值 $rows = array(); //debug( $data->sheets[0]['cells'] ); foreach ($data->sheets[0]['cells'] as $row) { for ($i = 1; $i <= $cols; $i++) { if (!isset($row[$i])) { $row[$i] = ''; } // 转换部门名称为部门id值 if ($i == 6 && !empty($row[$i])) { $row[$i] = get_group_id($row[$i]); } // 转换产品类型为id值 if ($i == 10) { $row[$i] = get_type_id($row[$i]); } // 生产数量如果为空,则置0 if ($i == 4 && empty($row[$i])) { $row[$i] = 0; } // 计划完成时间 if ($i == 5 && !empty($row[$i])) { $row[$i] = change_date_style($row[$i]); } } $rows[] = $row; } // 导入数据库 foreach ($rows as $row) { //debug( $row ); $prod = new \Model\Production(); $prod->num = $row[1]; $prod->name = $row[2]; $prod->graphic_num = $row[3]; $prod->count = $row[4]; $prod->planned_completion_date = $row[5]; $prod->graphic_src = $row[6]; $prod->use_dep = 18; $prod->completion_contact_person = $row[7]; $prod->completion_contact_phone = $row[8]; $prod->graphic_count = $row[9]; $prod->type = $row[10]; $prod->project_src = $row[11]; $prod->remark = $row[12]; $prod->user_id = $_SESSION['user_id']; if ($prod->is_valid()) { $prod->save(); } else { //debug( $prod->errors ); // 如果某条导入失败 // 记录该条目的生产指令号,产品名称 // 以及具体的错误原因 $errors = array(); foreach ($prod->errors as $error) { $errors[] = $error; } $results['failed_items'][] = array('num' => $prod->num, 'name' => $prod->name, 'errors' => $errors); } } //debug( $rows );*/ //debug( $rows ); //debug( $rows ); $results['is_success'] = true; } } } echo json_encode($results); }
echo _theme_footer(); } } else { //if($_FILES['uploadfile']['size']>0) if (strlen($HTTP_VARS['owner_id']) > 0) { if (strcmp($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')) === 0) { $page_title = get_opendb_lang_var('import_my_items'); } else { $page_title = get_opendb_lang_var('import_items_for_name', array('fullname' => fetch_user_name($HTTP_VARS['owner_id']), 'user_id' => $HTTP_VARS['owner_id'])); } } else { $page_title = get_opendb_lang_var('import_items'); } echo _theme_header($page_title); echo "<h2>" . $page_title . "</h2>"; echo format_error_block(get_opendb_lang_var('file_upload_empty', 'prompt', strtoupper(get_file_ext($_FILES['uploadfile']['name'])))); echo _theme_footer(); } } else { $importPlugin = new PreviewImportPlugin(); if (strcmp($HTTP_VARS['owner_id'], get_opendb_session_var('user_id')) === 0) { $page_title = get_opendb_lang_var('type_import', array('description' => $importPlugin->get_display_name())); } else { $page_title = get_opendb_lang_var('type_import_items_for_name', array('description' => $importPlugin->get_display_name(), 'fullname' => fetch_user_name($HTTP_VARS['owner_id']), 'user_id' => $HTTP_VARS['owner_id'])); } echo _theme_header($page_title); echo "<h2>" . $page_title . " " . get_item_image($HTTP_VARS['s_item_type']) . "</h2>\n"; // no upload file provided - so preview mode. echo get_uploaded_form($importPlugin, NULL, $HTTP_VARS); echo _theme_footer(); }
function get_item_display_field($item_r, $item_attribute_type_r, $value = NULL, $dowrap = TRUE, $prompt_mask = NULL) { if ($item_attribute_type_r['display_type'] == 'hidden') { return ''; } else { if ($item_attribute_type_r['display_type'] == 'fileviewer') { $format_mask = ifempty($item_attribute_type_r['display_type_arg1'], '%value%'); $width = ifempty($item_attribute_type_r['display_type_arg2'], '400'); $height = ifempty($item_attribute_type_r['display_type_arg3'], '300'); $target = ifempty($item_attribute_type_r['display_type_arg4'], '_blank'); if (is_array($value)) { $values = $value; } else { $values[] = $value; } if (count($values) > 0) { $display_value_r = array(); while (list(, $value) = each($values)) { $value = trim($value); $value_format_mask = $format_mask; if (strpos($value_format_mask, '%img%') !== FALSE) { $file_type_r = fetch_file_type_r(fetch_file_type_for_extension(get_file_ext($value))); if (strlen($file_type_r['image']) > 0 && ($image_src = theme_image_src($file_type_r['image'])) !== FALSE) { $img = '<img src="' . $image_src . '" title="' . $value . '">'; } else { $img = ''; } $value_format_mask = str_replace('%img%', $img, $value_format_mask); } if (strpos($value_format_mask, '%value%') !== FALSE) { $value_format_mask = str_replace('%value%', $value, $value_format_mask); } $file_r = file_cache_get_image_r($value, 'display'); $url = $file_r['fullsize']['url']; $display_value_r[] = "<a href=\"" . $value . "\" onclick=\"fileviewer('{$url}' ,'" . ($width + 20) . "', '" . ($height + 25) . "', '" . $target . "'); return false;\" title=\"" . $item_attribute_type_r['prompt'] . "\" class=\"popuplink\">{$value_format_mask}</a>"; } $field = format_multivalue_block($display_value_r, 'fileviewer'); if ($dowrap) { return format_field($item_attribute_type_r['prompt'], $field, $prompt_mask); } else { return $field; } } else { return ''; } } else { if ($item_attribute_type_r['display_type'] == 'datetime') { if (is_array($value)) { $values = $value; } else { $values[] = $value; } if (count($values) > 0) { $display_value_r = array(); while (list(, $value) = each($values)) { $value = trim($value); $timestamp = get_timestamp_for_datetime($value, 'YYYYMMDDHH24MISS'); if ($timestamp !== FALSE) { if (strlen($item_attribute_type_r['display_type_arg1']) == 0) { $item_attribute_type_r['display_type_arg1'] = 'DD/MM/YYYY'; } $datetime = get_localised_timestamp($item_attribute_type_r['display_type_arg1'], $timestamp); if ($datetime !== FALSE) { $display_value_r[] = $datetime; } else { $display_value_r[] = $value; } } else { $display_value_r[] = $value; } } $field = format_multivalue_block($display_value_r, 'datetime'); if ($dowrap) { return format_field($item_attribute_type_r['prompt'], $field, $prompt_mask); } else { return $field; } } else { return ''; } } else { if ($item_attribute_type_r['display_type'] == 'format_mins') { if (is_array($value)) { $values = $value; } else { $values[] = $value; } if (count($values) > 0) { $display_value_r = array(); while (list(, $value) = each($values)) { $value = trim($value); if (is_numeric($value)) { // Ensure we have a mask to work with. $display_mask = $item_attribute_type_r['display_type_arg1']; if (strlen($display_mask) == 0) { $display_mask = '%h %H %m %M'; } $hrs = floor($value / 60); // hours $mins = $value % 60; // minutes // Process display_mask and remove any bits that are not needed because the hour/minute is zero. if ($mins == 0 && $hrs > 0) { // only get rid of minutes if $hrs is a value. $index = strpos($display_mask, '%H'); if ($index !== FALSE) { $display_mask = substr($display_mask, 0, $index + 2); } else { $index = strpos($display_mask, '%m'); if ($index != FALSE) { $display_mask = substr($display_mask, 0, $index); } //include the %H } } else { if ($hrs == 0) { $index = strpos($display_mask, '%m'); if ($index != FALSE) { $display_mask = substr($display_mask, $index); } //include the %H } } // Unfortunately we need to do $mins>0 and $hrs>0 if's twice, because otherwise once we // replace the %h and %H the test for $mins>0 would not be able to cut the display_mask, // based on the %h/%H... if ($hrs > 0) { // Now do all replacements. $display_mask = str_replace('%h', $hrs, $display_mask); if ($hrs != 1) { $display_mask = str_replace('%H', get_opendb_lang_var('hours'), $display_mask); } else { $display_mask = str_replace('%H', get_opendb_lang_var('hour'), $display_mask); } } if ($mins >= 0 || $hrs === 0 && $mins === 0) { // Now do minute replacements only. $display_mask = str_replace('%m', $mins, $display_mask); if ($mins != 1) { $display_mask = str_replace('%M', get_opendb_lang_var('minutes'), $display_mask); } else { $display_mask = str_replace('%M', get_opendb_lang_var('minute'), $display_mask); } } $display_value_r[] = $display_mask; } else { // what else can we do here?! $display_value_r[] = $value; } } $field = format_multivalue_block($display_value_r, 'format_mins'); if ($dowrap) { return format_field($item_attribute_type_r['prompt'], $field, $prompt_mask); } else { return $field; } } else { return ''; } } else { if ($item_attribute_type_r['display_type'] == 'star_rating') { // arg[0] = rating range if (is_array($value)) { $values = $value; } else { $values[] = $value; } if (count($values) > 0) { $display_value_r = array(); while (list(, $value) = each($values)) { $value = trim($value); // no point unless numeric if (is_numeric($value)) { $total_count = $item_attribute_type_r['display_type_arg1']; if (is_numeric($total_count)) { $display_value = ''; $j = $value; for ($i = 0; $i < $total_count; ++$i) { if ($j >= 0.75) { $display_value .= theme_image('rs.gif'); } else { if ($j >= 0.25) { $display_value .= theme_image('rgs.gif'); } else { $display_value .= theme_image('gs.gif'); } } $j = $j - 1; } $ratingmask = $item_attribute_type_r['display_type_arg2']; if (strlen($ratingmask) > 0) { $ratingmask = str_replace('%value%', $value, $ratingmask); $ratingmask = str_replace('%maxrange%', $total_count, $ratingmask); $display_value = str_replace('%starrating%', $display_value, $ratingmask); } if ($item_attribute_type_r['listing_link_ind'] == 'Y') { $display_value = format_listing_link($value, $display_value, $item_attribute_type_r, NULL); } } $display_value_r[] = $display_value; } } $field = format_multivalue_block($display_value_r, 'starrating'); if ($dowrap) { return format_field($item_attribute_type_r['prompt'], $field, $prompt_mask); } else { return $field; } } else { return ''; // nothing to do! } } else { if (!is_array($value) && $item_attribute_type_r['display_type'] == 'display' && ifempty($item_attribute_type_r['display_type_arg1'], '%value%') == '%value%') { // Support newline formatting by default. $value = nl2br(trim($value)); if ($item_attribute_type_r['listing_link_ind'] == 'Y') { $field = format_listing_links($value, $item_attribute_type_r, 'exact'); } else { $field = $value; } if ($dowrap) { return format_field($item_attribute_type_r['prompt'], $field, $prompt_mask); } else { return $field; } } else { if ($item_attribute_type_r['display_type'] == 'list') { //list(list_type [,delimiter]) if (is_array($value)) { $values = $value; $attr_match = 'exact'; } else { $value = trim($value); if (strlen($item_attribute_type_r['display_type_arg2']) == 0) { // Use newline! $values = explode_lines($value); $attr_match = 'partial'; } else { $values = explode($item_attribute_type_r['display_type_arg2'], $value); if (strlen(trim($item_attribute_type_r['display_type_arg2'])) === 0) { $attr_match = 'word'; } else { $attr_match = 'partial'; } } } $field = format_list_from_array($values, $item_attribute_type_r, $item_attribute_type_r['listing_link_ind'] == 'Y' ? $attr_match : FALSE); if ($dowrap) { return format_field($item_attribute_type_r['prompt'], $field, $prompt_mask); } else { return $field; } } else { if ($item_attribute_type_r['display_type'] == 'category' || $item_attribute_type_r['display_type'] == 'display') { $field = ''; if (is_array($value)) { $value_array = $value; } else { $value_array[] = $value; } $attribute_value_rs = array(); if ($item_attribute_type_r['lookup_attribute_ind'] == 'Y') { $results = fetch_value_match_attribute_type_lookup_rs($item_attribute_type_r['s_attribute_type'], $value_array, get_lookup_order_by($item_attribute_type_r['display_type_arg1']), 'asc'); if ($results) { while ($lookup_r = db_fetch_assoc($results)) { $lookup_key = array_search2($lookup_r['value'], $value_array, TRUE); if ($lookup_key !== FALSE) { // Remove the matched element array_splice($value_array, $lookup_key, 1); $attribute_value_rs[] = array(value => $lookup_r['value'], display => $lookup_r['display'], img => $lookup_r['img']); } } db_free_result($results); } } // where extra items that do not have a matching lookup value. if (is_not_empty_array($value_array)) { reset($value_array); while (list(, $value) = each($value_array)) { if (strlen(trim($value)) > 0) { // In case there are extra spaces $attribute_value_rs[] = array(value => $value, display => $value); } } } if (is_not_empty_array($attribute_value_rs)) { $field = format_lookup_display_block($item_attribute_type_r, $attribute_value_rs); if (strlen($field) > 0) { if ($dowrap) { return format_field($item_attribute_type_r['prompt'], $field, $prompt_mask); } else { return $field; } } else { return NULL; } } } else { if ($item_attribute_type_r['display_type'] == 'review') { $total_count = fetch_attribute_type_cnt('S_RATING'); if (is_numeric($total_count)) { $value = trim($value); if (!is_numeric($value)) { $value = 0; } $field = ''; $j = $value; for ($i = 0; $i < $total_count; ++$i) { if ($j >= 0.75) { $field .= theme_image('rs.gif'); } else { if ($j >= 0.25) { $field .= theme_image('rgs.gif'); } else { $field .= theme_image('gs.gif'); } } $j = $j - 1; } // If a mask is defined, format the display value. if (strlen($item_attribute_type_r['display_type_arg1']) > 0) { $lookup_r = fetch_attribute_type_lookup_r('S_RATING', $value); if (is_not_empty_array($lookup_r)) { $field .= format_display_value($item_attribute_type_r['display_type_arg1'], $lookup_r['img'], $lookup_r['value'], $lookup_r['display']); } } return $field; // this is only used in a few places. } } } } } } } } } } //else -- no display type match. if ($dowrap) { return format_field($item_attribute_type_r['prompt'], nl2br($value), $prompt_mask); } else { return nl2br($value); } }
function SearchUsers($uids, $city, $district, $street, $startage = '', $endage = '', $gender = '', $hasQQ = false, $hasMSN = false, $hasPhone = false, $hastouxiang = false, $page, $pageSize, $paging = true, $current_uid = '', $checkFollowMe = false, $province = '', $orderBy = 'lastlogin') { $sql = "select u.push_uid,u.channel_id,u.device_type, u.password, case when u.gendar=1 then '他' when u.gendar=2 then '她' else 'TA' end as gendar_txt1,case when u.gendar=1 then '男' when u.gendar=2 then '女' else '未填写' end as gendar_txt,u.uid,u.uname,u.face_url,u.aboutme,u.uemail,u.birthday,u.lastlogintime,UNIX_TIMESTAMP(u.birthday) as bint,u.gendar,u.fans_count,u.topic_count,u.follow_count,u.province,u.city,u.area,u.street,u.qq,u.phone,u.msn,u.secondemail,u.realname,u.regdate,"; $sql .= "(select count(*) from userpoints where uid=u.uid and point_type='fans') as gpoints,"; $sql .= "(select count(*) from buddys where uid=u.uid and isfriend=1) as friend_count,"; $sql .= "(select name from common_district where id=u.province) as province_name,"; $sql .= "(select name from common_district where id=u.city) as city_name,"; $sql .= "(select name from common_district where id=u.area) as district_name,"; $sql .= "(select name from common_district where id=u.street) as street_name "; if ($current_uid != '' && $current_uid > 0) { $sql .= ",(select isfriend from buddys where buddyid=u.uid and uid={$current_uid}) as isfriend "; $sql .= ",(select isfollowed from buddys where buddyid=u.uid and uid={$current_uid}) as isfollowed "; } if ($checkFollowMe) { $sql .= ",(select isfriend from buddys where buddyid={$current_uid} and uid=u.uid) as followme "; } // $sql.="(select id from buddys where uid=$loginId and buddyid=u.uid) as bid"; $sql .= "from user u "; $sqlcount = "select count(u.uid) as rs from user u "; $where = "where 1=1 "; $orderby = "order by u.lastlogintime desc "; switch ($orderBy) { case "lastpost": $orderby = "order by u.lastposttime desc "; break; case "fanscount": $orderby = "order by u.fans_count desc "; break; case "name": $orderby = "order by u.uname asc "; break; case "lastlogin": $orderby = "order by u.lastlogintime desc "; break; default: $orderby = "order by u.lastlogintime desc "; break; } $limit = ''; if ($page > 0) { if ($pageSize == "" || $pageSize == 0) { $pageSize = $this->Config['building_topic_pagesize']; } $startrecord = $pageSize * ($page - 1); $endrecord = $pageSize * $page; $limit = ' limit ' . $startrecord . ',' . $pageSize; } if ($uids && $uids != '') { $where .= "and u.uid in ({$uids}) "; } if ($province && $province != '') { $where .= "and u.province in ({$province}) "; } if ($city && $city != '') { $where .= "and u.city in ({$city}) "; } if ($district && $district != '') { $where .= "and u.area in ({$district}) "; } if ($street && $street != '') { $where .= "and u.street in ({$street}) "; } if ($startage && $startage != '') { $where .= "and u.birthday >= '{$startage}' "; } if ($endage && $endage != '') { $where .= "and u.birthday <= '{$endage}' "; } if ($gender && $gender != '') { $where .= "and u.gendar={$gender} "; } if ($hastouxiang) { $where .= "and u.face_url<>'' "; } if ($hasPhone && $hasPhone == true) { $where .= "and u.phone<>'' "; } if ($hasQQ && $hasQQ == true) { $where .= "and u.qq <>'' "; } if ($hasMSN && $hasMSN == true) { $where .= "and u.msn<>'' "; } $result = array(); $result['data'] = array(); $result['total'] = 0; //$this->Logger->Write($sqlcount.$where); $totalRow = $this->DatabaseHandler->FetchFirst($sqlcount . $where); if ($totalRow) { $result['total'] = $totalRow['rs']; } if ($result['total'] == 0) { return $result; } if ($paging) { $query = $this->DatabaseHandler->Query($sql . $where . $orderby . $limit); } else { $query = $this->DatabaseHandler->Query($sql . $where . $orderby); } $this->Logger->Write($sql . $where . $orderby . $limit); $list = array(); if ($query) { $rows = $query->GetAll(); foreach ($rows as $row) { $image = $row['face_url']; if ($image && $image != '') { $image_prefix = GetImagePrefix($image); } $image_profile_img = $image_prefix . "_p." . get_file_ext($image); if (file_exists($image_profile_img)) { $row['face_url_p'] = $image_profile_img; } else { $row['face_url_p'] = $row['face_url']; } $row['image_prefix'] = $image_profile_img; $cdate = date('Y'); $bdate = date('Y', $row['bint']); $row['age'] = $cdate - $bdate; $row['lastlogin'] = getTime($row['lastlogintime']); $row['regdate'] = getTime($row['regdate']); $list[] = $row; } } $result['data'] = $list; return $result; }
function fp_loadfile($Frm, $Err) { if (!$Err) { $order_id = $Frm->GetNmValueI('order_id'); $file = $Frm->GetNmValue('file'); if (is_uploaded_file($file["tmp_name"])) { $extension = get_file_ext($file['name']); $new_name = trim($Frm->GetNmValueH('new_name')); if ($new_name == "") { $name = $file["name"]; } else { $name = $new_name . '.' . $extension; } $file_id = OrderFile::create(array('order_id' => $order_id, 'creator_id' => $_SESSION["user"]["data"]["id"], 'created' => time(), 'name' => $name, 'size' => $file["size"])); if (!$file_id) { $Frm->_gui->ERR("Ошибка при загрузке"); } else { $dir = DIR_FS_ORDER_FILES . $order_id . '/'; if (!is_dir(DIR_FS_ORDER_FILES)) { create_path('order_files', DIR_FS_DOCUMENT_ROOT); } if (!is_dir($dir)) { create_path($order_id, DIR_FS_ORDER_FILES); } $file_name = $file_id . '.' . $extension; if (move_uploaded_file($file['tmp_name'], $dir . $file_name)) { $Frm->_gui->OK("Файл загружен"); if ($_SESSION["user"]["data"]["group_id"] == 6 && get_order_author_id($order_id) == $_SESSION["user"]["data"]["id"]) { $res = change_order_status($order_id, 'RECEIVED_FILE_FROM_AUTHOR'); if ($res == 1) { $Frm->_gui->OK("Статус заказа изменен"); } else { $Frm->_gui->ERR($res); } } } else { OrderFile::delete($file_id); $Frm->_gui->ERR("Ошибка при сохранении файла"); } } page_reloadAll(); } } }
/** * Reads the contents of DIR_PUB.$url and write it to the output buffer. * * @param string $url */ function read_file_ext($url) { global $mime_types; $ext = get_file_ext($url); // Get the content type from the file. if (isset($mime_types[$ext])) { // Send the 'Content-Type' header. header('Content-Type: ' . $mime_types[$ext]); // Send 'Last-Modified' header. header('Last-Modified: ' . date('r', filemtime(DIR_PUB . $url))); // Directly read the file contents to output buffer. readfile(DIR_PUB . $url); } else { // if content type is not defined throw HTTP 403 error (forbidden) redirect(403, ERROR_403, $url); } }
function EditForm() { $id = (int) get('id', 0); if ($id) { $row = $this->getRow($id); $type = $row['html'] ? 'html' : 'img'; } else { $row['id'] = $id; $row['visible'] = 1; $row['target'] = 1; $row['position'] = ''; $row['root_id'] = get('root_id', '100'); $columns = sql_getRows('SHOW COLUMNS FROM banners', true); if (isset($columns['alt_image'])) { $row['alt_image'] = ''; } if (isset($columns['show_at_sites'])) { $row['show_at_sites'] = ''; } $type = 'image'; } $GLOBALS['title'] = $this->str($id ? 'edit' : 'add'); $this->AddStrings($row); $row['visible_checked'] = $row['visible'] ? 'checked' : ''; if (!empty($row['pages'])) { $row['pages_checked'] = 'checked'; } if (isset($row['image']) && is_file(".." . $row['image'])) { $ext = strtolower(get_file_ext($row['image'])); $size = getimagesize(".." . $row['image']); // Рисуем картинку if ($ext == '.gif' || $ext == '.jpg' || $ext == '.png') { $row['img_preview'] = '<img src="' . $row['image'] . '" ' . $size[3] . ' alt="" />'; } elseif ($ext == '.swf') { $row['img_preview'] = str_replace(array('{filename}', '{width}', '{height}'), array($row['image'], $size[0], $size[1]), $this->swf_code); } } if (isset($row['alt_image']) && is_file(".." . $row['alt_image'])) { $ext = strtolower(get_file_ext($row['alt_image'])); $size = getimagesize(".." . $row['alt_image']); // Рисуем картинку if ($ext == '.gif' || $ext == '.jpg' || $ext == '.png') { $row['alt_img_preview'] = '<img src="' . $row['alt_image'] . '" ' . $size[3] . ' alt="" />'; } } $row['options_target'] = $this->GetArrayOptions(array('_self', '_blank'), $row['target'], true, true); // Список положений баннера foreach ($this->position as $key => $val) { $options_pos[$key] = utf($val['display'][int_langId()]); } $row['options_pos'] = $this->GetArrayOptions($options_pos, $row['position'], true, false); // Список сайтов if (isset($row['show_at_sites'])) { global $site_domains; $sites = array(); $root = domainRootID(); foreach ($site_domains as $key => $val) { foreach ($val['langs'] as $l) { if ($l['root_id'] != $root) { $sites[$l['root_id']] = (LANG_SELECT && !empty($val['descr_' . lang()]) ? $val['descr_' . lang()] : (!empty($val['descr']) ? $val['descr'] : $val['name'])) . ' (' . $l['descr'] . ')'; } } } $row['sites'] = $sites; if (!empty($row['show_at_sites'])) { $row['show_at_sites'] = explode(",", $row['show_at_sites']); } } // Список вариантов для редактирования баннеров $options_type = array('img', 'html'); $row['options_type'] = $this->GetArrayOptions($options_type, $type, false, true); // Текст для HTML баннера include_fckeditor(); $oFCKeditor = new FCKeditor(); $oFCKeditor->ToolbarSet = 'Common'; $oFCKeditor->Value = isset($row['html']) ? $row['html'] : ''; $row['html'] = $oFCKeditor->ReturnFCKeditor('fld[html]', '100%', '300px'); return $this->Parse($row, $this->name . '.editform.tmpl'); }
function file_cache_insert_file($url, $location, $content_type, $content, $cache_type = 'HTTP', $overwrite = FALSE) { $cache_config_r = file_cache_get_config($cache_type); if (is_array($cache_config_r) && $cache_config_r['enable'] !== FALSE) { $directory = $cache_config_r['directory']; if ($directory === FALSE) { return FALSE; } // we need to know whether we are overwriting existing URL or not $file_cache_r = fetch_url_file_cache_r($url, $cache_type, INCLUDE_EXPIRED); if (is_array($file_cache_r)) { if (!file_cache_get_cache_file($file_cache_r)) { opendb_logger(OPENDB_LOG_INFO, __FILE__, __FUNCTION__, 'Cache file record exists, but there is no cache file - will recreate', $file_cache_r); $file_cache_r['cache_file'] = NULL; // delete thumbnail if it exists if (!($thumbnail_file = file_cache_get_cache_file_thumbnail($file_cache_r))) { delete_file($thumbnail_file); } $file_cache_r['cache_file_thumb'] = NULL; } else { if (!$overwrite) { opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, 'File cache record exists and cannot be overwritten', $file_cache_r); return FALSE; } } } else { $file_cache_r['cache_type'] = $cache_type; } if ($content == NULL && is_url_absolute($url)) { $httpClient = new OpenDbSnoopy(); $content = $httpClient->fetchURI($url, FALSE); if ($content !== FALSE) { $location = $httpClient->getLocation(); $content_type = $httpClient->getContentType(); unset($httpClient); } else { unset($httpClient); // http client logs error return FALSE; } } $file_cache_r['url'] = ifempty($url, $file_cache_r['url']); $file_cache_r['location'] = ifempty($location, $file_cache_r['location']); $file_cache_r['content_type'] = validate_content_type(ifempty($content_type, $file_cache_r['content_type'])); $thumbnail_support = FALSE; if (strlen($file_cache_r['content_type']) > 0) { $file_type_r = fetch_file_type_r($file_cache_r['content_type']); $file_cache_r['extension'] = $file_type_r['extension']; $thumbnail_support = $file_type_r['thumbnail_support_ind'] == 'Y'; } else { $extension = get_file_ext($file_cache_r['url']); if (strlen($extension) > 0 && ($ext_content_type = fetch_file_type_for_extension($extension)) !== FALSE) { $content_type = $ext_content_type; } else { $content_type = validate_content_type($content_type); } $file_type_r = fetch_file_type_r($content_type); if (!is_array($file_type_r)) { opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, 'Content type not supported', array($url, $location, $content_type, $cache_type, $overwrite)); return FALSE; } $file_cache_r['content_type'] = $content_type; $file_cache_r['extension'] = $file_type_r['extension']; $thumbnail_support = $file_type_r['thumbnail_support_ind'] == 'Y'; } $file_cache_r['content_length'] = 0; if (($uploadFile = get_item_input_file_upload_url($url)) !== FALSE) { $file_cache_r['content_length'] = @filesize($uploadFile); $file_cache_r['cache_file'] = basename($uploadFile); $file_cache_r['upload_file_ind'] = 'Y'; } else { if (strlen($content) > 0) { $file_cache_r['content_length'] = strlen($content); $file_cache_r['upload_file_ind'] = 'N'; } } if ($file_cache_r['content_length'] > 0) { if (!is_numeric($file_cache_r['sequence_number'])) { $file_cache_r['sequence_number'] = insert_file_cache($cache_type, $file_cache_r['upload_file_ind'], $file_cache_r['url'], $file_cache_r['location'], $file_cache_r['content_type']); if ($file_cache_r['sequence_number'] === FALSE) { return FALSE; } } if ($file_cache_r['cache_file'] == NULL) { $file_cache_r['cache_file'] = filecache_generate_cache_filename($file_cache_r); } if ($content != NULL) { $directory = file_cache_get_cache_type_directory($file_cache_r['cache_type']); $cacheFile = $directory . '/' . $file_cache_r['cache_file']; if (!file_put_contents($cacheFile, $content) !== FALSE) { opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, 'Cache file not written', array($cacheFile)); return FALSE; } } if ($thumbnail_support) { if (strlen($file_cache_r['cache_file_thumb']) == 0) { $file_cache_r['cache_file_thumb'] = filecache_generate_cache_filename($file_cache_r, TRUE); } } if ($file_cache_r['upload_file_ind'] != 'Y') { $expire_date = is_numeric($cache_config_r['lifetime']) ? "NOW()+ INTERVAL " . $cache_config_r['lifetime'] . " SECOND" : NULL; } else { $expire_date = NULL; } // do not expire uploaded file records. if (!update_file_cache($file_cache_r['sequence_number'], $file_cache_r['content_length'], $expire_date, $file_cache_r['cache_file'], $file_cache_r['cache_file_thumb'])) { return FALSE; } if ($thumbnail_support) { file_cache_save_thumbnail_file($file_cache_r, $errors); } return TRUE; } else { opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, 'File content length is zero', array($url, $location, $content_type, $cache_type, $overwrite)); return FALSE; } } else { if (!is_array($cache_config_r)) { opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, 'No file cache configuration', array($url, $location, $content_type, $cache_type, $overwrite)); return FALSE; } else { // file cache is disabled return TRUE; } } }
/** * download images of an archive * @param Archive $archive */ protected function download_archive_images(Archive $archive) { $archive_start_at = microtime(true); $this->site->parse_archive($archive); $all_count = count($archive->images); $done_count = 0; $digit = strlen($all_count); $digit = $digit > 3 ? $digit : 3; $this->log('archive_start', date('Y-m-d H:i:s', $archive_start_at) . ' ' . $archive->id . " {$all_count} images start"); for ($i = 0; $i < $all_count; $i++) { if (PHP_OS == 'WINNT') { $title = iconv(strtoupper($archive->site->charset), strtoupper($GLOBALS['app_config']['win_charset']), $archive->title); } if ($archive->cover_mode) { $archive_folder = ''; $file_name = $archive->id . '_' . $title . '.' . get_file_ext($archive->images[$i]); // we need a shorter $file_id to write in log because $file_name would be too long sometimes. $file_id = $archive->id . '_.' . get_file_ext($archive->images[$i]); } else { $archive_folder = $archive->id . '_' . $title . '/'; $file_name = $archive->id . '_' . sprintf("%0{$digit}d", $i + 1) . '.' . get_file_ext($archive->images[$i]); $file_id = $file_name; } $save_path = ROOTPATH . 'storage/images/' . $this->config['save_folder'] . $archive_folder; mkdir_ex($save_path); $file = $save_path . $file_name; if (file_exists($file)) { $done_count++; continue; } // to do: detect file size & type $image_start_at = microtime(true); $result = curl_download($archive->images[$i], $file); $image_end_at = microtime(true); if ($result['status']['flag']) { $line = date('Y-m-d H:i:s', $image_end_at) . ' ' . $file_id . ' ok ' . sprintf('%.1fs', $image_end_at - $image_start_at); $this->log('image_done', $line); $done_count++; } else { unlink($file); $line = date('Y-m-d H:i:s', $image_end_at) . ' ' . $file_id . ' error ' . sprintf('%.1fs', $image_end_at - $image_start_at); $this->log('image_error', $line); } // usleep(mt_rand(200, 500)); } $archive_end_at = microtime(true); if ($done_count < $all_count) { $line = date('Y-m-d H:i:s', $archive_end_at) . ' ' . $archive->id . " {$done_count}/{$all_count}" . ' done(need redo) ' . sprintf('%.1fs', $archive_end_at - $archive_start_at); $this->log('archive_done', $line); return false; } else { $line = date('Y-m-d H:i:s', $archive_end_at) . ' ' . $archive->id . " {$done_count}/{$all_count}" . ' done ' . sprintf('%.1fs', $archive_end_at - $archive_start_at); $this->log('archive_done', $line); return true; } }
function get_file_path($order_id, $file) { $extension = get_file_ext($file['name']); return DIR_FS_ORDER_FILES . $order_id . '/' . $file['id'] . '.' . $extension; }
function import() { // 施工员/调度员 四车间 if (!has_perm(1, 4) && !has_perm(2, 4)) { exit; } $name = $_FILES['files']['name'][0]; $size = $_FILES['files']['size'][0]; $tmp_name = $_FILES['files']['tmp_name'][0]; if (get_file_ext($name) != 'xls') { $results['error'] = '对不起,系统只允许上传扩展名为 <strong>xls</strong> 的电子表格文件!'; $results['is_success'] = false; } else { if ($size > 2000000) { $results['error'] = '对不起,系统只允许上传小于 <strong>2M</strong> 的电子表格文件!'; $results['is_success'] = false; } else { if (!empty($tmp_name)) { $data = new \Spreadsheet_Excel_Reader(); $data->setOutputEncoding('UTF-8'); $cols = 6; /* 每一行有6个单元格 */ $rows = array(); $data->read($tmp_name); error_reporting(E_ALL ^ E_NOTICE); // 对电子表格的每一行进行循环 // 检测到某个单元格不存在时,设定其为空值 foreach ($data->sheets[0]['cells'] as $row) { for ($i = 1; $i <= $cols; $i++) { if (!isset($row[$i])) { $row[$i] = ''; } // 计划完成时间 if ($i == 6 && !empty($row[$i])) { $row[$i] = change_date_style($row[$i]); } } $rows[] = $row; } //debug( $rows ); // 导入数据库 foreach ($rows as $row) { $prod_num = $row[1]; $prod = Production::find_by_num($prod_num); // 当这条零件记录所对应的生产指令 prod 存在时 if (!empty($prod)) { $part = new \Model\Part(); $part->production_id = $prod->id; $part->num = $row[2]; $part->name = $row[3]; $part->graphic_num = $row[4]; $part->count = $row[5]; $part->planned_completion_date = $row[6]; $part->user_id = $_SESSION['user_id']; if ($part->is_valid()) { $part->save(); } else { // 如果某条导入失败 // 记录该条目的零件指令号,零件名称 // 以及具体的错误原因 $errors = array(); foreach ($part->errors as $error) { $errors[] = $error; } $results['failed_items'][] = array('num' => $part->num, 'name' => $part->name, 'errors' => $errors); } } } //debug( $results['failed_items'] ); $results['is_success'] = true; } } } echo json_encode($results); }
function EditForm() { $id = (int) get('id', 0); if ($id) { $row = $this->getRow($id); $type = $row['html'] ? 'html' : 'img'; } else { $row['id'] = $id; $row['visible'] = 1; $row['target'] = 1; $row['position'] = ''; $row['root_id'] = get('root_id', '100'); $type = 'image'; } $GLOBALS['title'] = $this->str($id ? 'edit' : 'add'); $this->AddStrings($row); $row['visible_checked'] = $row['visible'] ? 'checked' : ''; if (!empty($row['pages'])) { $row['pages_checked'] = 'checked'; } if (isset($row['image']) && is_file(".." . $row['image'])) { $ext = strtolower(get_file_ext($row['image'])); $size = getimagesize(".." . $row['image']); // Рисуем картинку if ($ext == '.gif' || $ext == '.jpg' || $ext == '.png') { $row['img_preview'] = '<img src="' . $row['image'] . '" ' . $size[3] . ' alt="" />'; } elseif ($ext == '.swf') { $row['img_preview'] = str_replace(array('{filename}', '{width}', '{height}'), array($row['image'], $size[0], $size[1]), $this->swf_code); } } $row['options_target'] = $this->GetArrayOptions(array('_self', '_blank'), $row['target'], true, true); // Список положений баннера foreach ($this->position as $key => $val) { $options_pos[$key] = utf($val['display'][int_langId()]); } $row['options_pos'] = $this->GetArrayOptions($options_pos, $row['position'], true, false); // Список вариантов для редактирования баннеров $options_type = array('img', 'html'); $row['options_type'] = $this->GetArrayOptions($options_type, $type, false, true); // Текст для HTML баннера include_fckeditor(); $oFCKeditor = new FCKeditor(); $oFCKeditor->ToolbarSet = 'Common'; $oFCKeditor->Value = $row['html']; $row['html'] = $oFCKeditor->ReturnFCKeditor('fld[html]', '100%', '300px'); return $this->Parse($row, $this->name . '.editform.tmpl'); }
simple_query($sql); if($row['linedate_viewed'] == "0000-00-00 00:00:00") { $sql = " update log_email set linedate_viewed = now() where id = '$row[id]' "; simple_query($sql); } if($row['tmp_filename'] == '') { $file_uuid = createuuid(); $file_ext = get_file_ext($row['attachment']); $tmp_filename = "$file_uuid.$file_ext"; $sql = " update log_email set tmp_filename = '".sql_friendly($tmp_filename)."' where id = '".sql_friendly($row['id'])."' "; simple_query($sql); } else { $tmp_filename = $row['tmp_filename']; }
function filename($filepath) { return basename($filepath, "." . get_file_ext($filepath)); }
function getFiles($dir) { if (substr($dir, -1) != "/") { $dir .= "/"; } $files = array(); $k = 1; if ($handle = @opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..' && substr($file, 0, 1) != '.' && !is_dir($dir . $file)) { $size = is_file($dir . $file) ? filesize($dir . $file) : -1; $size = $this->formatSize($size); $files[] = array('id_num' => $k, 'id' => e(h($file)), 'name' => h($file), 'size' => $size, 'ext' => substr(get_file_ext($file), 1), 'perms' => file_GetPermsInfo(@fileperms($dir . $file))); $k++; } } closedir($handle); } usort($files, "sort_files"); return $files; }
for ($i = 0; $i < count($array1); $i += 2) { $down_filenames[] = $array1[$i]; $down_filedescs[] = $array1[$i + 1]; } for ($i = 0; $i < count($down_ext); $i++) { $down_files["" . $down_ext[$i] . ""] = array(); $down_descs["" . $down_ext[$i] . ""] = array(); } //echo("open dir ".$vars['dir_downloads']."<br>"); $dir = opendir($vars['dir_downloads']); while ($file = readdir($dir)) { //echo("$file<br>"); if ($file != "." && $file != "..") { $ok = false; for ($i = 0; $i < count($down_ext); $i++) { if (get_file_ext($file) == $down_ext[$i]) { $ok = true; } } if ($ok == true) { $down_files["" . get_file_ext($file) . ""][] = $file; $file_desc = ""; for ($j = 0; $j < count($down_filenames); $j++) { if ($down_filenames[$j] == $file) { $file_desc = $down_filedescs[$j]; } } $down_descs[get_file_ext($file)][] = $file_desc; } } }
private function copy($data) { $folder = get_data($data, 'folder'); $from = get_data($data, 'from'); $to = get_data($data, 'to'); if ($folder != 'ftp_draws' && $folder != 'ftp_photos') { $this->echo_error('folder undefined'); return; } if ($from == '' || $to == '') { $this->echo_error('missing [where] statement'); return; } $directory = DOCUMENT_ROOT . 'uploads/' . $folder . '/'; $source = $directory . $from . '.*'; $copied = 0; foreach (glob($source) as $filename) { // echo $filename . ", size: " . filesize($filename) . "\n"; $ext = get_file_ext($filename); $dest = $directory . $to . '.' . $ext; if (copy($filename, $dest)) { $copied++; } } $return = array(); $return['status'] = 'ok'; $return['copied'] = $copied; echo json_encode($return); }
$zakname = $HTTP_POST_FILES["down_file"]["name"]; $error = false; for ($i = 0; $i < count($down_ext); $i++) { for ($j = 0; $j < count($down_files[$down_ext[$i]]); $j++) { if ($zakname == $down_files[$down_ext[$i]][$j]) { echo $language['version_1.6'][26]; echo "<br><a href=?p={$p}&forum_ext={$forum_ext}&id=downloads>" . $language['version_1.6'][28] . "</a>"; $error = true; } } } if ($error == false) { $ok = false; for ($i = 0; $i < count($down_ext); $i++) { //echo($down_ext."==".get_file_ext($zakname)."<br>"); if ($down_ext[$i] == get_file_ext($zakname)) { $ok = true; } } if ($ok == false) { echo $language['version_1.6'][35]; echo "<br><a href=?p={$p}&forum_ext={$forum_ext}&id=downloads>" . $language['version_1.6'][28] . "</a>"; $error = true; } } if ($error == false) { if (filesize($zak) > $vars['file_maxsize'] * 1024) { echo $language['version_1.6'][29] . "" . $vars['file_maxsize'] . "" . $language['version_1.6'][31]; echo "<br><a href=?p={$p}&forum_ext={$forum_ext}&id=downloads>" . $language['version_1.6'][28] . "</a>"; $error = true; }
<?php /** * 使用curl提交图片到zimg服务器上 */ $img_host = 'http://127.0.0.1:4869'; //图片服务器 $zimg_upload_url = $img_host . '/upload'; // 上传图片到zimg图片存储服务 foreach ($_FILES as $file) { $ch = curl_init(); // 关键在这里! $post_data = file_get_contents($file['tmp_name']); // raw_post方式 $ext = get_file_ext($file['name']); $headers = array(); $headers[] = 'Content-Type:' . $ext; // 还有这里! curl_setopt($ch, CURLOPT_URL, $zimg_upload_url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //启用时会发送一个常规的POST请求,类型为:application/x-www-form-urlencoded,就像表单提交的一样。 curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $info = curl_exec($ch); curl_close($ch); //var_dump($info); $json = json_decode($info, true); $signature = $json['info']['md5'];
function validate_item_input_field($item_attribute_type_r, $value, &$errors) { // cater for multivalue fields here! if (!is_array($value) && strlen(trim($value)) > 0) { $tmpval = trim($value); unset($value); $value[] = $tmpval; } if ($item_attribute_type_r['compulsory_ind'] == 'Y') { // at this point, $value will always be an array because of the block above. if (is_empty_or_not_array($value)) { $error = array('error' => get_opendb_lang_var('prompt_must_be_specified', 'prompt', $item_attribute_type_r['prompt']), 'detail' => ''); if (is_array($errors)) { $errors[] = $error; } else { $errors = $error; } return FALSE; } } if (is_not_empty_array($value) && $item_attribute_type_r['lookup_attribute_ind'] != 'Y') { switch ($item_attribute_type_r['input_type']) { case 'hidden': case 'readonly': case 'textarea': case 'htmlarea': case 'text': case 'password': case 'simple_checkbox': case 'checkbox': case 'check_boxes': // deprecated // deprecated case 'vertical_check_boxes': // deprecated // deprecated case 'horizontal_check_boxes': // deprecated // deprecated case 'radio_group': // deprecated // deprecated case 'vertical_radio_group': // deprecated // deprecated case 'horizontal_radio_group': // deprecated // deprecated case 'radio_grid': case 'value_radio_grid': case 'checkbox_grid': case 'single_select': case 'multi_select': case 'value_select': return TRUE; break; case 'url': // will be an array of content groups if (strlen($item_attribute_type_r['input_type_arg3']) > 0) { $content_group_r = prc_args($item_attribute_type_r['input_type_arg3']); $extensions_r = fetch_file_type_extensions_r($content_group_r); // it might just be a list of extensions if (!is_not_empty_array($extensions_r)) { $extensions_r = $content_group_r; } for ($i = 0; $i < count($value); $i++) { if (!in_array(strtolower(get_file_ext($value[$i])), $extensions_r)) { $error = array('error' => get_opendb_lang_var('url_is_not_valid', array('prompt' => $item_attribute_type_r['prompt'], 'extensions' => implode(', ', $extensions_r))), 'detail' => ''); if (is_array($errors)) { $errors[] = $error; } else { $errors = $error; } return FALSE; } } } //else return TRUE; case 'email': for ($i = 0; $i < count($value); $i++) { if (!is_valid_email_addr($value[$i]) && ($item_attribute_type_r['compulsory_ind'] == 'Y' && strlen(trim($value[$i])) > 0)) { $error = array('error' => get_opendb_lang_var('email_is_not_valid', 'prompt', $item_attribute_type_r['prompt']), 'detail' => ''); if (is_array($errors)) { $errors[] = $error; } else { $errors = $error; } return FALSE; } } //else return TRUE; case 'datetime': for ($i = 0; $i < count($value); $i++) { if ($item_attribute_type_r['compulsory_ind'] == 'Y' || strlen(trim($value[$i])) > 0) { $timestamp = get_timestamp_for_datetime($value[$i], $item_attribute_type_r['input_type_arg1']); if ($timestamp === FALSE) { //else perhaps it is a timestamp value already. $timestamp = get_timestamp_for_datetime($value[$i], 'YYYYMMDDHH24MISS'); if ($timestamp === FALSE) { $error = array('error' => get_opendb_lang_var('datetime_is_not_valid', array('prompt' => $item_attribute_type_r['prompt'], 'format_mask' => $item_attribute_type_r['input_type_arg1'])), 'detail' => ''); if (is_array($errors)) { $errors[] = $error; } else { $errors = $error; } return FALSE; } } } } //else return TRUE; case 'filtered': $legalChars = expand_chars_exp($item_attribute_type_r['input_type_arg3']); for ($i = 0; $i < count($value); $i++) { $value[$i] = trim($value[$i]); for ($j = 0; $j < strlen($value[$i]); $j++) { if (strstr($legalChars, substr($value[$i], $j, 1)) === FALSE) { $error = array('error' => get_opendb_lang_var('prompt_must_be_format', array('prompt' => $item_attribute_type_r['prompt'], 'format' => '[' . $item_attribute_type_r['input_type_arg3'] . ']')), 'detail' => ''); if (is_array($errors)) { $errors[] = $error; } else { $errors = $error; } return FALSE; } } } return TRUE; case 'number': for ($i = 0; $i < count($value); $i++) { if (!is_numeric($value[$i]) && ($item_attribute_type_r['compulsory_ind'] == 'Y' && strlen(trim($value[$i])) > 0)) { $error = array('error' => get_opendb_lang_var('prompt_must_be_format', array('prompt' => $item_attribute_type_r['prompt'], 'format' => '[0-9]')), 'detail' => ''); if (is_array($errors)) { $errors[] = $error; } else { $errors = $error; } return FALSE; } } return TRUE; default: return TRUE; break; } } else { return TRUE; } }
if ($create_track_image) { //track image auslesen $imagefilename = $NL[0]['track_image']; //wenn "_global": if ($imagefilename == "_global") { //bildname uebergeben, evtl ist es "_blank" //einstellungen aus der config uebernehmen: $imagefilename = $C[0]['track_image']; } //"_blank"? if ($imagefilename == "_blank") { $Image = makeBlankImage(4, 7); } //wenn kein blank oder global if ($imagefilename != "_blank" && $imagefilename != "_global") { $TrackImageType = strtolower(get_file_ext($imagefilename)); if ($TrackImageType == "jpeg") { $TrackImageType = "jpg"; } $imagefile = $tm_nlimgpath . "/" . $imagefilename; //wenn die datei existiert: if (file_exists($imagefile)) { $Image = makeTrackImage($imagefile, $TrackImageType); } else { //wenn die datei nicht existiert, blank! $Image = makeBlankImage(4, 7); } } } #Header("content-type: image/".$TrackImageType); // Image output
<?php include_once 'application.php'; if (!empty($_FILES)) { $new_folder = $defaultsarray['base_path'] . "uploads/"; $def_access = $defaultsarray['default_attachment_access_level']; if (!file_exists($new_folder)) { mkdir($new_folder); } $file_ext = get_file_ext($_FILES['Filedata']['name']); $new_filename = get_unique_filename($new_folder, $_FILES['Filedata']['name']); $curdate = 0; if (move_uploaded_file($_FILES['Filedata']['tmp_name'], $new_folder . $new_filename)) { $curdate = mrr_pull_image_created_date($new_folder . $new_filename); $rslt = 1; } else { $rslt = 0; } $user_id = 0; $store_id = 0; $merchant_id = 0; if (isset($_SESSION['user_id'])) { $user_id = $_SESSION['user_id']; } if (isset($_SESSION['store_id'])) { $store_id = $_SESSION['store_id']; } if (isset($_SESSION['merchant_id'])) { $merchant_id = $_SESSION['merchant_id']; } //log that file was uploaded...