function lxfile_dstat($dir, $duflag) { $dir = expand_real_root($dir); $list = lscandir_without_dot($dir); $ret = null; foreach ($list as $l) { $stat = lstat("{$dir}/{$l}"); get_file_type("{$dir}/{$l}", $stat); remove_unnecessary_stat($stat); if ($duflag && is_dir("{$dir}/{$l}") || $l === ".trash") { $stat['size'] = lxfile_dirsize("{$dir}/{$l}", true); } else { $stat['size'] = lxfile_size("{$dir}/{$l}"); } $stat['name'] = "{$dir}/{$l}"; $ret[] = $stat; } //dprintr($ret); return $ret; }
public function update() { //传阅 $model = M('Files_user'); $mu_data['fid'] = $_POST['id']; $users = $model->where($mu_data)->select(); if ($_POST['user']) { if ($users) { $up_data['fid'] = $_POST['id']; $up_sdata['title'] = $_POST['title']; $model->where($up_data)->save($up_sdata); foreach ($_POST['user'] as $key => $user) { $user_arr = explode(',', $user); $ids[] = $user_arr[0]; } foreach ($users as $user) { if (array_search($user['user_id'], $ids) === false) { //删除参会人员 $del_data['id'] = $user['id']; $model->where($del_data)->delete(); } } //unset($ids); foreach ($users as $user) { $ids2[] = $user['user_id']; } foreach ($_POST['user'] as $user) { $user_arr = explode(',', $user); if (array_search($user_arr[0], $ids2) === false) { if ($_POST['call_time']) { $add_data['call_time'] = strtotime($_POST['call_time']); } //添加 $add_data['fid'] = $_POST['id']; $add_data['user_id'] = $user_arr[0]; $add_data['user_name'] = $user_arr[1]; $add_data['bm_name'] = $user_arr[2]; $add_data['title'] = $_POST['title']; $model->add($add_data); } } } else { //添加 foreach ($_POST['user'] as $key => $user) { if ($_POST['call_time']) { $add_data['call_time'] = strtotime($_POST['call_time']); } $add_data['fid'] = $_POST['id']; $user_arr = explode(',', $user); $add_data['user_id'] = $user_arr[0]; $add_data['user_name'] = $user_arr[1]; $add_data['bm_name'] = $user_arr[2]; $add_data['title'] = $_POST['title']; $model->add($add_data); } } } else { $del_data['fid'] = $_POST['id']; $model->where($del_data)->delete(); } //附件处理 $model = M('attachments'); $a_data['source'] = MODULE_NAME; $a_data['sourceid'] = $_POST['id']; $model->where($a_data)->delete(); //echo $model->getlastsql();exit; if ($_POST['uppicarr']) { $model = M('attachments'); foreach ($_POST['uppicarr'] as $key => $file) { $add_data['source'] = MODULE_NAME; $add_data['sourceid'] = $_POST['id']; $add_data['filepath'] = $file; $file_dir = str_replace(C('IMG_URL'), C('IMG_ROOT'), $file); $add_data['size'] = filesize($file_dir); $add_data['type'] = get_file_type($file_dir); $add_data['filename'] = $add_data['title'] = $_POST['uppicname'][$key]; $add_data['create_time'] = time(); $add_data['user_id'] = $_SESSION[C('USER_AUTH_KEY')]; $model->add($add_data); //echo $model->getlastsql();exit; } } $model = M('Files'); $vo_data['id'] = $_POST['id']; $vo = $model->where($vo_data)->find(); if ($vo['type'] == 1 && $_POST['type'] == 1) { //内部文档变更 $this->update_date($ids2, $_POST['id'], 'del'); $this->update_date($ids, $_POST['id'], 'add'); } else { if ($vo['type'] == 1 && $_POST['type'] == 2) { //内部文档改外部文档 $this->update_date($ids2, $_POST['id'], 'del'); unset($ids); $ids[] = 0; $this->update_date($ids, $_POST['id'], 'add'); } } if ($vo['type'] == 2 && $_POST['type'] == 1) { //外部文档改内部文档 unset($ids2); $ids2[] = 0; $this->update_date($ids2, $_POST['id'], 'del'); $this->update_date($ids, $_POST['id'], 'add'); } if (false === $model->create()) { //$this->error ( $model->getError () ); $msg['status'] = 0; $msg['notice'] = $model->getError(); $msg['error_code'] = 8002; echo json_encode($msg); exit; } // 更新数据 $list = $model->save(); $this->update_file_users($_POST['id']); $msg['status'] = 1; $msg['notice'] = '编辑成功!'; $msg['error_code'] = 8002; echo json_encode($msg); exit; //$this->success ('编辑成功!'); }
if ($hide_header) { if ($item === 'HEADER' || $item === 'HEADER.html') { continue; } } if ($hide_readme) { if ($item === 'README' || $item === 'README.html') { continue; } } if ($show_hidden_files == "false") { if (substr($item, 0, 1) == "." or substr($item, -1) == "~") { continue; } } $filelist[] = array('name' => $item, 'size' => filesize($path . '/' . $item), 'modtime' => filemtime($path . '/' . $item), 'file_type' => get_file_type($path . '/' . $item), 'counter' => get_download_count($item), 'img_id' => get_file_type_id($path . '/' . $item)); } } closedir($handle); } if (!isset($_GET['sort'])) { $_GET['sort'] = 'name'; } // Figure out what to sort files by $file_order_by = array(); foreach ($filelist as $key => $row) { $file_order_by[$key] = $row[$_GET['sort']]; } // Figure out what to sort folders by $folder_order_by = array(); foreach ($folderlist as $key => $row) {
/** * 查看订单详情 * @author 李东 * @date 2015-06-30 */ public function detail() { $order_id = I('get.id'); if (!$order_id) { $this->error('错误操作'); } $map['order_id'] = $order_id; $order_info = get_info(D($this->model), $map); if ($order_info['order_status'] == 1) { redirect(U('/Home/Buy/confirm_quote/', array('order_id' => $order_id))); } $files = get_result($this->files_complete, array('order_id' => $order_id)); // print_r($files);exit; $order_info['files'] = $files; /*获取格式为 id=>title 的语言分类数组*/ $language_text = id_and_text(get_language_cache()); /*获取格式为 id=>title 的领域分类数组*/ $industry_text = id_and_text(get_industry_cache()); /*获取格式为 id=>title 的属性分类数组*/ $ability_text = id_and_text(get_ability_cache()); /*获取格式为 id=>title 的产品分类数组*/ $product_type = id_and_text($this->product_type); /*暂时将一维数组转化为二维数组*/ $temp[] = $order_info; $temp = int_to_string($temp, array("order_status" => $this->order_status, 'is_need_invoice' => array('0' => '否', '1' => '是'), 'product_type' => $product_type, 'pay_type' => array('0' => '余额支付', '1' => '支付宝支付'), "product_language_id" => $language_text, "product_to_language_id" => $language_text)); /*将Json中所有ID转换成文字字符串*/ $temp = json_to_chars($temp, array('product_industry_id' => $industry_text, 'product_ability_id' => $ability_text)); $order_info = $temp[0]; /*将二维数组还原成一维数组*/ /*获取买家信息*/ $buyer_info = get_info('member', array('id' => $order_info['member_id'])); /*获取下单地址信息*/ $user_address = get_area_pid($order_info['address_path'] . $order_info['address_id']); /*获取发票信息*/ if ($order_info['is_need_invoice'] == 1) { $invoice = get_address_detail($order_info['address_id']); } $address_text = ''; foreach ($user_address as $row) { $address_text .= $row['title'] . ' '; } $buyer_info['address_text'] = $address_text; $map = array(); $map['order_id'] = $order_id; $order_result = get_result('order_history', $map); $order_result = int_to_string($order_result, array('order_status' => $this->order_status)); if ($order_info['order_status'] == 4) { /*如果订单状态为待退款状态,查询退款原因描述*/ $map['order_id'] = $order_id; $refund_result = get_result(D($this->refund_model), $map); // print_r($refund_result);exit; foreach ($refund_result as $k => $row) { if ($row['type'] == 1) { /*如果是下单用户的信息,查询是否上传凭证文件*/ $refund_result[$k]['ask_name'] = $row['username']; $files = get_result($this->refund_files, array('refund_id' => $row['id'])); $files = get_file_type($files); $refund_result[$k]['files'] = $files; } elseif ($row['type']) { $refund_result[$k]['ask_name'] = $row['shop_title']; } } } $data['invoice'] = $invoice; $data['info'] = $order_info; $data['result'] = $order_result; $data['buyer_info'] = $buyer_info; $data['refund_result'] = $refund_result; $this->assign($data); $this->display(); }
public static function read_dir_ext($dir, $ext) { $files = array(); $dirct = opendir($dir); while ($file = readdir($dirct)) { if ($file != "." && $file != ".." && is_file($dir . "/" . $file) && get_file_type($file) == $ext) { $files[] = $file; } } return $files; }
function get_file_info($type, $file_path, $ffmpeg = '') { $result = FALSE; if ($file_path) { $info_file = meta_file_path($type, $file_path); $result = file_get($info_file); if (!$result) { if (file_exists($file_path)) { $check = array(); switch ($type) { case 'type': // do nothing if file doesn't already exist // do nothing if file doesn't already exist case 'http': case 'ffmpeg': break; case 'Server': // HTTP header data // HTTP header data case 'ETag': case 'Date': case 'Last-Modified': case 'Content-Length': case 'Content-Type': $check['http'] = TRUE; break; case 'dimensions': if (get_file_type($file_path) == 'image') { // we can get dimensions of images with php $check['php'] = TRUE; break; } case 'duration': /* for when we can get duration of audio from php if (get_file_type($file_path) == 'audio') { $check['php'] = TRUE; break; } */ /* for when we can get duration of audio from php if (get_file_type($file_path) == 'audio') { $check['php'] = TRUE; break; } */ case 'fps': // only from FFMPEG // only from FFMPEG case 'audio': $check['ffmpeg'] = TRUE; break; default: // something other than http info needed switch (get_file_type($file_path)) { case 'image': case 'video': case 'audio': break; default: // couldn't get media type or type unrecognizable $check['http'] = TRUE; } } if (!empty($check['php'])) { // for now just images supported $data = @getimagesize($file_path); if ($data && $data[0] && $data[1]) { $result = $data[0] . 'x' . $data[1]; } } if (!empty($check['ffmpeg'])) { $data = get_file_info('ffmpeg', $file_path); if (!$data) { if ($ffmpeg) { $cmd = $ffmpeg; $cmd .= ' -i ' . $file_path; $data = shell_command($cmd); set_file_info($file_path, 'ffmpeg', $data); } } if ($data) { $result = ffmpeg_info_from_string($type, $data); } } if (!empty($check['http'])) { $data = get_file_info('http', $file_path); if ($data) { $data = http_info_from_string($type, $data); if ($data) { $result = $data; } } } // try to cache the data for next time set_file_info($file_path, $type, $result); } } } return $result; }
} else { $parent_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset(getMatrixFolderId(trim($import_dir), $matrix_ids)); // overwrite the import path because we are using fullpath $import_path = $import_dir; } if (is_null($parent_asset)) { trigger_error("New parent asset #{$parent_assetid} does not exist\n", E_USER_ERROR); } $import_link = array('asset' => $parent_asset, 'link_type' => SQ_LINK_TYPE_1); // get a list of all files in the import directory $files = list_files($import_path); if ($SORTING) { sort($files); } foreach ($files as $filename) { switch (get_file_type($filename)) { case 'doc': case 'dot': $new_asset_type = 'word_doc'; break; case 'pdf': $new_asset_type = 'pdf_file'; break; case 'gif': case 'jpg': case 'jpeg': case 'png': $new_asset_type = 'image'; break; case 'xls': $new_asset_type = 'excel_doc';
function dirlist($dir = '.', $currdir = '.', $prefix = ' ') { // Recursive function to list out directories, subdirectories, and their files. global $DIRLIST_LINK_TEMPLATE; global $menu_index; $dirpath = realpath($currdir . '/' . $dir); if ($dh = @opendir($dirpath)) { // Fill array with file names. $files = array(); while (($file = readdir($dh)) !== false) { if ($file == '.') { continue; } if ($file == '..') { continue; } //////////////////////// // Filter files here. // //////////////////////// // no filters... $files[] = $file; } closedir($dh); sort($files, SORT_STRING); // List directories first for ($i = 0; $i < count($files); $i++) { $file = $files[$i]; if (!is_dir($dirpath . '/' . $file)) { continue; } $symbol = menu_symbol($menu_index); $class = ' class="' . menu_li_class($menu_index) . '"'; $style = ' style="' . menu_ul_style($menu_index) . '"'; $menu_index++; print "\n{$prefix}<li{$class}>{$symbol}{$file}"; print "\n{$prefix} <ul{$style}>"; // Recursive call. dirlist($file, ($currdir ? "{$currdir}/" : '') . $dir, $prefix . ' '); print "\n{$prefix} </ul>"; print "\n{$prefix}</li>"; } // List files next for ($i = 0; $i < count($files); $i++) { $file = $files[$i]; if (is_dir($dirpath . '/' . $file)) { continue; } $symbol = '<span class="' . get_file_type($file) . '"></span>'; if ($DIRLIST_LINK_TEMPLATE) { $link = $DIRLIST_LINK_TEMPLATE; $link = preg_replace('/\\$file/', $file, $link); $linkdir = $currdir . '/' . $dir; $linkdir = preg_replace('|^(\\./)+|', '', $linkdir); $link = preg_replace('/\\$dir/', $linkdir, $link); } else { $link = $file; } print "\n{$prefix}<li>{$symbol}{$link}</li>"; } } else { //print "\n<br>Cannot open $dirpath."; $symbol = '<span class="symbol-error"></span>'; print "\n{$prefix}<li>{$symbol}{$dir}</li>"; } }
/** * * @param <type> $mime_type * @return <type> */ function show_cache_file($mime_type) { // use browser cache if available to speed up page load if (!empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { if (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) < strtotime('now')) { header('HTTP/1.1 304 Not Modified'); die; } } $cache_file = get_cache_file(); if (file_exists($cache_file)) { // change the modified headers $gmdate_expires = gmdate('D, d M Y H:i:s', strtotime('now +10 days')) . ' GMT'; $gmdate_modified = gmdate('D, d M Y H:i:s') . ' GMT'; // send content headers then display image header('Content-Type: image/' . get_file_type($mime_type)); header('Accept-Ranges: none'); header('Last-Modified: ' . $gmdate_modified); header('Content-Length: ' . filesize($cache_file)); header('Cache-Control: max-age=' . CACHE_MAX_AGE . ', must-revalidate'); header('Expires: ' . $gmdate_expires); if (!@readfile($cache_file)) { $content = file_get_contents($cache_file); if ($content != FALSE) { echo $content; } else { display_error('cache file could not be loaded'); } } die; } return FALSE; }
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data = curl_exec($ch); curl_close($ch); if ($data) { return $data; } else { echo "?"; } } $url = $_GET["url"]; // first, confirm the URL exists if (!url_exists($url)) { echo "{ \"success\": false, \"message\": \"Sorry, that URL doesn't seem to contain an image!\" }"; exit; } // second, that it's a filetype we can work with $extension = get_file_type($url); if (!in_array($extension, array("png", "gif", "jpg"))) { echo "{ \"success\": false, \"message\": \"Sorry, please only supply URLs of images in PNG, GIF and JPG format.\" }"; exit; } // okay, now lets make a copy of it locally with a random filename, and return that to the client $image_data = curl_file_get_contents($url); $filename = "tmp" . time() . "." . $extension; $fh = fopen(dirname(__FILE__) . "/../remote/{$filename}", "w"); fwrite($fh, $image_data); fclose($fh); echo "{ \"success\": true, \"message\": \"{$filename}\" }"; exit;
function get_preview($format, $type, $url) { $result = ""; if (get_file_type($format) == "image") { $result = '<img src="' . $url . '" style="max-width:400px;" />'; } if (get_file_type($format) == "audio") { $result = '<audio controls><source src="' . $url . '" type="' . $type . '">Your browser does not support the audio element. </audio>'; } if (get_file_type($format) == "video") { $result = '<video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" width="640" height="264" poster="" data-setup="{}"> <source src="' . $url . '" type="' . $type . '" /> <p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p> </video>'; } return $result; }
/** * Gets information about the raw HTTP request. */ function get_http_request() { $url_parts = get_url_parts(); $path = '/' . implode('/', $url_parts); $is_logout = $path == '/logout'; $method = strtoupper(trim($_SERVER['REQUEST_METHOD'])); $verified_user_id = 0; $login_id = null; $name = null; $is_admin = false; $ip = trim($_SERVER['REMOTE_ADDR']); $content = null; $form = array(); $content_type = null; $raw_content = null; $files = array(); $cookies = array(); foreach ($_COOKIE as $k => $v) { $cookies[$k] = $v; } if ($method != 'GET') { $content_type = trim(isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : $_SERVER['HTTP_CONTENT_TYPE']); if (strpos($content_type, 'application/x-www-form-urlencoded') === 0 || strpos($content_type, 'multipart/form-data') === 0) { foreach ($_POST as $key => $value) { $form[$key] = $value; } foreach ($_FILES as $key => $value) { $file_info = array('id' => $key, 'mime' => $value['type'], 'type' => get_file_type($value['type']), 'size' => $value['size'], 'path' => $value['tmp_name'], 'is_image' => false); if ($file_info['type'] == 'PNG' || $file_info['type'] == 'JPEG' || $file_info['type'] == 'GIF') { $file_info['is_image'] = true; $dim = @getimagesize($file_info['path']); if (is_array($dim) && count($dim) >= 2) { $file_info['image_width'] = $dim[0]; $file_info['image_height'] = $dim[1]; } } array_push($files, $file_info); } } else { $raw_content = file_get_contents('php://input'); } } $session_token = trim($cookies['nptoken']); $client = trim($cookies['npclient']); $ttl_hours = 24 * 30; // change this for other clients upon request. if (!$is_logout && isset($form['login_username'])) { $login_result = api_account_create_session($login_result['name'], $form['login_password'], $client, $ip, $ttl_hours); if ($login_result['status'] == 'OK') { $user_id = $login_result['user_id']; $session_token = $login_result['token']; } } $login_failure = false; $user_info = null; if (!$is_logout && strlen($session_token) > 0) { $user_info = api_account_authenticate_with_session($session_token, $ip); if ($user_info['status'] != 'OK') { $user_info = null; $login_failure = true; } } if ($user_info !== null) { $verified_user_id = $user_info['user_id']; $is_admin = $user_info['is_admin']; $login_id = $user_info['login_id']; $name = $user_info['name']; $avatar = $user_info['avatar']; } if ($is_logout) { $session_token = ''; } setcookie('npclient', 'web', $expire); setcookie('nptoken', $session_token, $expire); return array('method' => $method, 'path' => $path, 'path_parts' => $url_parts, 'user_id' => $verified_user_id, 'login_id' => $login_id, 'logged_in' => $verified_user_id > 0, 'login_failure' => $login_failure, 'name' => $name, 'is_admin' => $is_admin, 'content_type' => $content_type, 'form' => $form, 'raw_content' => $raw_content, 'files' => $files, 'cookies' => $cookies, 'ip' => $ip, 'avatar' => $avatar, 'now' => time()); }
$folderlist = array(); $filelist = array(); if ($handle = @opendir($path)) { while (($item = readdir($handle)) !== false) { if (in_array($item, $excludeArray)) { continue; } if (is_dir($path . '/' . $item) and $item != '.' and $item != '..') { $folderlist[] = array('name' => $item, 'size' => $calculate_folder_size ? foldersize($path . '/' . $item) : 0, 'modtime' => filemtime($path . '/' . $item), 'file_type' => "Directory"); } elseif (is_file($path . '/' . $item)) { if (!$show_hidden_files) { if (substr($item, 0, 1) == "." or substr($item, -1) == "~") { continue; } } $filelist[] = array('name' => $item, 'size' => filesize($path . '/' . $item), 'modtime' => filemtime($path . '/' . $item), 'file_type' => get_file_type($path . '/' . $item)); } } fclose($handle); } if (!isset($_GET['sort'])) { $_GET['sort'] = $defaultSortField; } // Figure out what to sort files by $file_order_by = array(); foreach ($filelist as $key => $row) { $file_order_by[$key] = $row[$_GET['sort']]; } // Figure out what to sort folders by $folder_order_by = array(); foreach ($folderlist as $key => $row) {
#!/usr/bin/php <?php $username_password = file_get_contents('.github_userpwd'); // Delete old downloads first foreach (json_decode(file_get_contents('https://api.github.com/repos/gboudreau/Greyhole/downloads')) as $download) { delete_download($download->id, $download->name); } // Find files to upload $version = $argv[1]; foreach (glob("release/*{$version}*") as $file) { $filename = basename($file); if (strpos($filename, 'hda-greyhole-') !== FALSE || strpos($filename, '.src.rpm') !== FALSE || strpos($filename, 'greyhole-web-app') !== FALSE || strpos($filename, '.armv5tel.') !== FALSE) { // Skip those files continue; } $file_type = get_file_type($filename); $description = "Greyhole {$version} ({$file_type})"; echo "Uploading {$filename} with description {$description}...\n"; // Create the download metadata on Github $response = create_download($filename, filesize($file), $description); // Upload the actual file on Amazon S3 upload_file($file, $response); } function delete_download($id, $filename) { global $username_password; $url = "https://api.github.com/repos/gboudreau/Greyhole/downloads/{$id}"; echo "DELETE {$url} ({$filename})\n"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');