本文整理汇总了PHP中file_ext函数的典型用法代码示例。如果您正苦于以下问题:PHP file_ext函数的具体用法?PHP file_ext怎么用?PHP file_ext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file_ext函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importCartshop
static function importCartshop($tmp_file, $file, &$out)
{
global $CONFIG, $ST;
$dir = 'shared/php/';
include "{$dir}PHPExcel.php";
include "{$dir}PHPExcel/IOFactory.php";
PHPExcel_Settings::setLocale('ru');
if (file_ext($file) == 'xlsx') {
$objReader = new PHPExcel_Reader_Excel2007();
} elseif (file_ext($file) == 'xls') {
$objReader = new PHPExcel_Reader_Excel5();
}
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($tmp_file);
/*$objPHPExcel->setActiveSheetIndex(0);
$objWorksheet = $objPHPExcel->getActiveSheet();
$keys=array();
$keys_flg=array('category_id'=>'id',
'parent_id'=>'parentid',
'name'=>'name',
'description'=>'description',
'image_name'=>'img',
'sort_order'=>'main_sort',
);
$out=array();
foreach ($objWorksheet->getRowIterator() as $row) {
$data=array();
$field=array();
$field_ext=array();
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
$fld_flg=false;//Строка поля
$no_user_itm='';
foreach ($cellIterator as $cell) {
$val=trim(u2w($cell->getValue()));
if(!$fld_flg && $val=='category_id'){
$fld_flg=true;
}
if($fld_flg){//Грузим поля
if(isset($keys_flg[$val])){
$keys[$cell->getColumn()]=$keys_flg[$val];
}
// print_r($keys);
continue;
}
if($keys && isset($keys[$cell->getColumn()])){
if(is_integer($keys[$cell->getColumn()])){
$field["{$keys[$cell->getColumn()]}"]=$val;
}else{
$field_ext["{$keys[$cell->getColumn()]}"]=$val;
}
}
}
if(!$keys){
continue;
}
if(!empty($field_ext['id'])){
if($field_ext['img']){
if($img=@file_get_contents('http://www.farmcosmetica.ru/image/'.$field_ext['img'])){
$img_name=preg_replace('|^data/|','',$field_ext['img']);
$img_name=str_replace('/','_',$img_name);
$img_name="storage/catalog/".$img_name;
if(!file_exists($img_name)){
file_put_contents($img_name,$img);
}
$field_ext['img']="/".$img_name;
}else{
$field_ext['img']="";
}
}
$rs=$ST->select("SELECT * FROM sc_shop_catalog WHERE id={$field_ext['id']}");
if($rs->next()){
$ST->update('sc_shop_catalog',$field_ext,"id={$field_ext['id']}");
}else{
$ST->insert('sc_shop_catalog',$field_ext);
}
$out[$field_ext['id']]=$field_ext;
}
}
*/
$objPHPExcel->setActiveSheetIndex(1);
$objWorksheet = $objPHPExcel->getActiveSheet();
$keys = array();
$keys_flg = array('product_id' => 'id', 'categories' => 'categories', 'name' => 'name', 'quantity' => 'in_stock', 'image_name' => 'img', 'additional image names' => 'img_add', 'price' => 'price', 'date_added' => 'insert_time', 'date_modified' => 'update_time', 'viewed' => 'views', 'description' => 'html');
$out = array();
foreach ($objWorksheet->getRowIterator() as $row) {
//.........这里部分代码省略.........
示例2: file_down
function file_down($file, $filename = '', $data = '')
{
if (!$data && !is_file($file)) {
exit;
}
$filename = $filename ? $filename : basename($file);
$filetype = file_ext($filename);
$filesize = $data ? strlen($data) : filesize($file);
ob_end_clean();
@set_time_limit(0);
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
} else {
header('Pragma: no-cache');
}
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Content-Encoding: none');
header('Content-Length: ' . $filesize);
header('Content-Disposition: attachment; filename=' . $filename);
header('Content-Type: ' . $filetype);
if ($data) {
echo $data;
} else {
readfile($file);
}
exit;
}
示例3: pass
function pass($post)
{
global $DT_TIME, $MOD;
if (!is_array($post)) {
return false;
}
if (!$post['catid']) {
return $this->_(lang('message->pass_catid'));
}
if (strlen($post['title']) < 3) {
return $this->_(lang('message->pass_title'));
}
if (!$post['fileurl']) {
return $this->_(lang('message->pass_down_fileurl'));
}
$ext = file_ext($post['fileurl']);
if (in_array($ext, array('php', 'sql')) || strpos($post['fileurl'], '..') !== false) {
return $this->_(lang('message->pass_down_badurl'));
}
if (!$post['filesize']) {
return $this->_(lang('message->pass_down_filesize'));
}
if (DT_MAX_LEN && strlen($post['content']) > DT_MAX_LEN) {
return $this->_(lang('message->pass_max'));
}
return true;
}
示例4: NTConfigloaded
function NTConfigloaded()
{
$tmp_file = $_FILES['fichier']['tmp_name'];
$content_dir = dirname(__FILE__) . "/ressources/conf/upload";
if (!is_dir($content_dir)) {
mkdir($content_dir);
}
if (!is_uploaded_file($tmp_file)) {
up_iframe('{error_unable_to_upload_file}');
exit;
}
$type_file = $_FILES['fichier']['type'];
if (!strstr($type_file, 'application/octet-stream')) {
up_iframe('{error_file_extension_not_match} :' . $type_file . ' did not match application/octet-stream');
exit;
}
$name_file = $_FILES['fichier']['name'];
$ext = file_ext($name_file);
if (!strstr($ext, 'pol')) {
up_iframe('{error_file_extension_not_match} :.' . $ext . ' did not match .pol');
exit;
}
if (file_exists($content_dir . "/" . $name_file)) {
@unlink($content_dir . "/" . $name_file);
}
if (!move_uploaded_file($tmp_file, $content_dir . "/NTconfig.pol")) {
up_iframe("{error_unable_to_move_file} : {$content_dir}/NTconfig.pol");
exit;
}
$_GET["moved_file"] = $content_dir . "/" . $name_file;
$res = "{success}";
$sock = new sockets();
$sock->getfile("PushNTconfig:{$content_dir}/NTconfig.pol");
up_iframe($res);
}
示例5: f_img_resize
function f_img_resize($path, $w, $h, $watermark = null)
{
if (!$path) {
return;
}
//Image::configure(array('driver' => 'gd'));
$path_0 = $path;
if (!file_exists(WEB . $path_0)) {
return;
}
$path = str_replace('/upload/', '/upload/thum/', $path);
$new = file_dir($path);
$ext = file_ext($path);
$new = $new . '/' . file_name($path) . "_{$w_}{$h}" . '.' . $ext;
if (file_exists(WEB . $new)) {
return $new;
}
echo WEB . $path_0;
$img = Image::make(WEB . $path_0);
$img->resize($w, $h);
if (!is_dir(WEB . file_dir($new))) {
mkdir(WEB . $new, 0777, true);
}
if ($watermark) {
$img->insert(WEB . $watermark);
}
$img->save(WEB . $new);
return $new;
}
示例6: remote
function remote($file, $savepath, $savename = '')
{
global $DT, $_userid;
$this->file = $file;
$this->userid = $_userid;
$this->ext = file_ext($file);
in_array($this->ext, array('jpg', 'jpeg', 'gif', 'png', 'bmp')) or $this->ext = 'jpg';
$this->maxsize = $DT['uploadsize'] ? $DT['uploadsize'] * 1024 : 2048 * 1024;
$this->savepath = $savepath;
$this->savename = $savename;
}
示例7: actUpload
function actUpload()
{
global $get;
if (isset($_FILES['upload'])) {
$name = md5_file($_FILES['upload']['tmp_name']) . '.' . file_ext($_FILES['upload']['name']);
$path = '/storage/temp/' . $name;
move_uploaded_file($_FILES['upload']['tmp_name'], ROOT . $path);
$img = scaleImg($path, $get->get('size'));
if ($get->get('resize') == 'true') {
$path = scaleImg($path, $get->get('size'));
}
}
echo printJSONP(array('msg' => 'Сохранено', 'path' => $path, 'img' => $img), $get->get('cb'));
exit;
}
示例8: http_upload
function http_upload($file)
{
$ext = file_ext($file);
$size = dround(filesize($file) / 1024);
if ($size < 1) {
return array('', 'invalid media file');
}
if ($ext == 'mp3' || $ext == 'amr') {
if ($size > 256) {
return array('', 'media file too large');
}
$type = 'voice';
} else {
if ($ext == 'mp4') {
if ($size > 1024) {
return array('', 'media file too large');
}
$type = 'video';
} else {
if ($ext == 'jpg') {
if ($size > 128) {
return array('', 'media file too large');
}
$type = 'image';
} else {
return array('', 'invalid media type');
}
}
}
$par = array();
$par['access_token'] = $this->access_token;
$par['type'] = $type;
$par['media'] = '@' . $file;
#$par = 'access_token='.$this->access_token.'&type='.$type.'&media=@'.$file;
$cur = curl_init('http://file.api.weixin.qq.com/cgi-bin/media/upload');
curl_setopt($cur, CURLOPT_POST, 1);
curl_setopt($cur, CURLOPT_POSTFIELDS, $par);
curl_setopt($cur, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($cur, CURLOPT_HEADER, 0);
curl_setopt($cur, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($cur, CURLOPT_RETURNTRANSFER, 1);
#curl_setopt($cur, CURLOPT_HTTPHEADER, array('Expect: '));
$rec = curl_exec($cur);
curl_close($cur);
$arr = json_decode($rec, true);
return isset($arr['media_id']) ? array($arr['media_id'], $type) : array('', $arr['errmsg']);
}
示例9: upload
function upload($_file, $savepath, $savename = '', $fileformat = '')
{
global $DT, $_userid;
foreach ($_file as $file) {
$this->file = $file['tmp_name'];
$this->file_name = $file['name'];
$this->file_size = $file['size'];
$this->file_type = $file['type'];
$this->file_error = $file['error'];
}
$this->userid = $_userid;
$this->ext = file_ext($this->file_name);
$this->fileformat = $fileformat ? $fileformat : $DT['uploadtype'];
$this->maxsize = $DT['uploadsize'] ? $DT['uploadsize'] * 1024 : 2048 * 1024;
$this->savepath = $savepath;
$this->savename = $savename;
}
示例10: actUpload
function actUpload()
{
global $get;
$num = '';
if (isset($_FILES['upload']) && $_FILES['upload']['name']) {
$name = md5_file($_FILES['upload']['tmp_name']) . '.' . file_ext($_FILES['upload']['name']);
$path = '/storage/temp/' . $name;
move_uploaded_file($_FILES['upload']['tmp_name'], ROOT . $path);
}
if (isset($_FILES['upload1']) && $_FILES['upload1']['name']) {
$num = '1';
$name = md5_file($_FILES['upload1']['tmp_name']) . '.' . file_ext($_FILES['upload1']['name']);
$path = '/storage/temp/' . $name;
move_uploaded_file($_FILES['upload1']['tmp_name'], ROOT . $path);
}
echo printJSONP(array('msg' => 'Сохранено', 'path' => $path, 'num' => $num), $get->get('cb'));
exit;
}
示例11: _xhUpload
/**
* xheditor专用上传
* @param string|array $files
* @param array $config 上传配置
* @param string $type 上传文件类型
*/
private function _xhUpload($files, $config = array(), $type = '')
{
$msg = null;
$error = null;
//上传配置
$config = array_merge(C('FILE_UPLOAD_CONFIG'), $config);
//HTML5上传
if (isset($_SERVER['HTTP_CONTENT_DISPOSITION']) && preg_match('/attachment;\\s+name="(.+?)";\\s+filename="(.+?)"/i', $_SERVER['HTTP_CONTENT_DISPOSITION'], $info)) {
$localName = urldecode($info[2]);
$ext = file_ext($localName);
if (!in_array($ext, $config['exts'])) {
$error = '上传文件后缀不允许';
} else {
$filename = UPLOAD_PATH . date('Y/m/d/') . uniqid() . '.' . $ext;
$res = file_write($filename, file_get_contents("php://input"));
if ($res) {
$msg = array('url' => file_path2url($filename), 'localname' => $localName);
} else {
$error = '上传失败';
}
}
} else {
$upload = new Upload($config);
$res = $upload->upload($files);
if ($res) {
$localName = $res['filedata']['name'];
$filename = UPLOAD_PATH . $res['filedata']['savepath'] . $res['filedata']['savename'];
$msg = array('url' => file_path2url($filename), 'localname' => $res['filedata']['name']);
} else {
$error = $upload->getError();
}
}
//针对xheditor不同上传类型返回不同结果
if ($msg) {
switch ($type) {
case 'link':
//附件类型,在URL中直接显示文件名称
$msg['url'] .= '||' . $localName;
break;
}
}
//返回上传结果
$this->ajaxReturn(json_encode(array('err' => $error, 'msg' => $msg)), 'eval');
}
示例12: create_plugin
function create_plugin($plugin_id, $url = "", $name = "")
{
$perfix_path = "plugins/{$name}/";
echo "<div id='plugin_{$plugin_id}'>";
/*,$css="",$js="",$call=""
if(!is_null($css) && ''!=$css)echo "<link href='$perfix_path$css' rel='stylesheet' type='text/css'>";
if(!is_null($js)&& ''!=$js) echo "<script type='text/javascript' src='$perfix_path$js'></script>";
if(!is_null($call)&& ''!=$call) echo "<script type='text/javascript'>$call</script>";
*/
if (!is_null($url) && '' != $url) {
if ("php" == substr(file_ext($url), 0, 3)) {
//echo ("http://".$_SERVER["HTTP_HOST"]getRootUrl().$url);
include_safe("{$perfix_path}" . $url);
} else {
include_once "{$perfix_path}" . $url;
}
}
echo "</div>";
}
示例13: actSave
function actSave()
{
global $post;
$id = $post->getInt('u_id');
$data = array('login' => $post->get('login'), 'status' => $post->get('status'), 'name' => $post->get('name'), 'company' => $post->get('company'), 'phone' => $post->get('phone'), 'city' => $post->get('city'), 'address' => $post->get('address'), 'mail' => $post->get('mail'), 'avat' => $post->get('avat'), 'balance' => $post->getFloat('balance'), 'discount' => $post->getFloat('discount'), 'hide' => 0, 'type' => $post->get('type'));
$password = $post->remove('password');
$avat_path = $post->remove('avat_path');
$msg = 'Сохранено';
$img_out = "";
if (!empty($_FILES['upload']['name']) && isImg($_FILES['upload']['name'])) {
$img = $this->cfg('AVATAR_PATH') . '/' . md5($_FILES['upload']['tmp_name']) . "." . file_ext($_FILES['upload']['name']);
move_uploaded_file($_FILES['upload']['tmp_name'], ROOT . $img);
$data['avat'] = $img;
$img_out = scaleImg($img, 'w200');
}
if ($post->getInt('clear')) {
$data['avat'] = '';
}
$err = array();
$rs = DB::select("SELECT * FROM sc_users WHERE login='" . SQL::slashes($post->get('login')) . "' AND u_id<>{$id}");
if ($rs->next()) {
$err['login'] = 'Пользователь существует';
}
if (!$err) {
if ($id === 0) {
$data[] = "password=MD5('" . trim($password) . "')";
$id = DB::insert('sc_users', $data, 'u_id');
} else {
if (trim($password)) {
$data[] = "password=MD5('" . trim($password) . "')";
}
DB::update('sc_users', $data, 'u_id=' . $id);
}
echo printJSONP(array('msg' => $msg, 'u_id' => $id, 'img' => $img_out));
exit;
} else {
echo printJSONP(array('err' => $err));
exit;
}
}
示例14: file_upload
function file_upload($name, $up_dir = null, $access = '', $filename = null)
{
if (empty($up_dir)) {
$up_dir = UPLOAD_DIR . "/" . date('Y') . date("m") . "/" . date("d");
}
$path = WEBPATH . $up_dir;
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
$mime = $_FILES[$name]['type'];
$filetype = file_gettype($mime);
if ($filetype == 'bin') {
$filetype = file_ext($_FILES[$name]['name']);
}
if ($filetype == false) {
echo "File Type Error!";
return false;
} elseif (!empty($access)) {
$access_type = explode(',', $access);
if (!in_array($filetype, $access_type)) {
echo "File Type '{$filetype}' not allow upload!";
return false;
}
}
if ($filename == null) {
$filename = substr(time(), 6, -1) . rand(100000, 999999);
}
$filename .= "." . $filetype;
if (move_uploaded_file($_FILES[$name]['tmp_name'], $path . "/" . $filename)) {
return "{$up_dir}/{$filename}";
} else {
echo "Error! debug:\n";
print_r($_FILES[$name]);
return false;
}
}
示例15: actSave
function actSave()
{
global $ST, $get, $post;
$id = $post->getInt('id');
$data = array('content' => $post->get('content'), 'description' => $post->get('description'), 'title' => $post->get('title'), 'author' => $post->get('author'), 'date' => dte($post->get('date'), 'Y-m-d'), 'state' => $post->get('state'), 'category' => $post->getInt('category'), 'position' => $post->getInt('position'), 'gallery' => $post->getInt('gallery'), 'type' => $this->getType());
$img_out = "";
if (!empty($_FILES['upload']['name']) && isImg($_FILES['upload']['name'])) {
$img = $this->cfg('NEWS_IMAGE_PATH') . '/' . md5($_FILES['upload']['tmp_name']) . "." . file_ext($_FILES['upload']['name']);
move_uploaded_file($_FILES['upload']['tmp_name'], ROOT . $img);
$data['img'] = $img;
$img_out = scaleImg($img, 'w200');
}
if ($post->getInt('clear')) {
$data['img'] = '';
}
if ($id) {
$ST->update('sc_news', $data, "id=" . $id);
} else {
$id = $ST->insert('sc_news', $data);
}
$ST->delete('sc_relation', "parent={$id} AND type='public'");
foreach ($post->getArray('public_rel') as $v) {
$ST->insert('sc_relation', array('parent' => $id, 'type' => 'public', 'child' => $v));
}
$msg = "Сохранено";
if (true) {
$content = '';
$content .= '<small>' . date('d.m.Y') . '</small> ';
$content .= '<strong>' . $post->getHtml('title') . '</strong><br />';
$content .= '<span>' . $post->getHtml('description') . '</span><br />';
$content .= '<a href="http://' . $this->cfg('SITE') . '/' . $post->get('type') . '/' . $id . '/">подробнее...</a>';
if ($post->exists('save_and_send')) {
$mail = new Mail();
$mail->setFromMail(array($this->cfg('SITE'), $this->cfg('mail')));
$key = 'http://' . $this->cfg('SITE') . '/cabinet/unsubscribe/?key=' . md5($this->getUser('mail') . $this->getType() . 'unsubscribe') . '&type=' . $this->getType() . '&mail=' . $this->getUser('mail');
$key = '<a href="' . $key . '">' . $key . '</a>';
$mail->setTemplate('letter_' . $this->getType(), array('FROM_SITE' => $this->cfg('SITE'), 'CONTENT' => $content, 'BODY' => $post->get('content'), 'TITLE' => $post->get('title')));
$mail->xsend($this->getUser('mail'), array('UNSUBSCRIBE' => $key));
} elseif ($post->exists('save_and_send_all')) {
$q = "SELECT distinct mail,id FROM sc_subscribe WHERE type LIKE '%" . $this->getType() . "%' \r\n\t\t\t\tAND NOT EXISTS(SELECT mailid FROM sc_news_sendlog WHERE id=mailid AND newsid={$id}){$this->getMailFilter()}";
if ($post->getInt('pack')) {
$q .= " LIMIT {$post->getInt('pack')}";
}
$rs = $ST->select($q);
$mail = new Mail();
// $mail->setFromMail($this->getConfig('mail'));
$mail->setFromMail(array($this->cfg('SITE'), $this->cfg('mail')));
$mail->setTemplate('letter_' . $this->getType(), array('FROM_SITE' => $this->cfg('SITE'), 'CONTENT' => $content, 'BODY' => $post->get('content'), 'TITLE' => $post->get('title')));
$n = 0;
while ($rs->next()) {
if (check_mail($m = trim($rs->get('mail')))) {
$key = 'http://' . $this->cfg('SITE') . '/cabinet/unsubscribe/?key=' . md5($rs->get('mail') . $this->getType() . 'unsubscribe') . '&type=' . $this->getType() . '&mail=' . $rs->get('mail');
$key = '<a href="' . $key . '">' . $key . '</a>';
$mail->xsend($m, array('UNSUBSCRIBE' => $key));
$ST->insert('sc_news_sendlog', array('mailid' => $rs->get('id'), 'newsid' => $id));
$n++;
} else {
$ST->delete('sc_subscribe', "mail='" . SQL::slashes($rs->get('mail')) . "'");
}
}
$msg .= " отправлено {$n}";
}
}
echo printJSONP(array('msg' => $msg, 'id' => $id, 'img' => $img_out));
exit;
}