当前位置: 首页>>代码示例>>PHP>>正文


PHP misc::clean_filename方法代码示例

本文整理汇总了PHP中misc::clean_filename方法的典型用法代码示例。如果您正苦于以下问题:PHP misc::clean_filename方法的具体用法?PHP misc::clean_filename怎么用?PHP misc::clean_filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在misc的用法示例。


在下文中一共展示了misc::clean_filename方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handleUpload

 function handleUpload($type, $edit, $owner)
 {
     // deals with incoming uploads
     global $config, $conn, $lang;
     require_once $config['basepath'] . '/include/misc.inc.php';
     $misc = new misc();
     $display = '';
     $file_x = 0;
     $edit = intval($edit);
     $owner = intval($owner);
     if ($type == 'user') {
         $sql = "SELECT count(" . $type . "images_id) as num_images FROM " . $config['table_prefix'] . "" . $type . "images WHERE (userdb_id = {$owner})";
     } else {
         $sql = "SELECT count(" . $type . "images_id) as num_images FROM " . $config['table_prefix'] . "" . $type . "images WHERE (listingsdb_id = {$edit})";
     }
     $recordSet = $conn->Execute($sql);
     if ($recordSet === false) {
         $misc->log_error($sql);
     }
     $num_images = $recordSet->fields['num_images'];
     $avaliable_images = $config['max_' . $type . '_uploads'] - $num_images;
     while ($file_x < $avaliable_images) {
         if (is_uploaded_file($_FILES['userfile']['tmp_name'][$file_x])) {
             $realname = $misc->clean_filename($_FILES['userfile']['name'][$file_x]);
             $filename = $_FILES['userfile']['tmp_name'][$file_x];
             $extension = substr(strrchr($realname, "."), 1);
             $filetype = $_FILES['userfile']['type'][$file_x];
             // checking the filetype to make sure it's what we had in mind
             $pass_the_upload = "true";
             if (!in_array($_FILES['userfile']['type'][$file_x], explode(',', $config['allowed_upload_types']))) {
                 $pass_the_upload = "{$realname} {$lang['upload_is_an_invalid_file_type']}: {$filetype}";
             }
             // check file extensions
             if (!in_array($extension, explode(',', $config['allowed_upload_extensions']))) {
                 $pass_the_upload = "{$lang['upload_invalid_extension']} ({$extension}).";
             }
             // check size
             $filesize = $_FILES['userfile']['size'][$file_x];
             if ($config['max_' . $type . '_upload_size'] != 0 && $filesize > $config['max_' . $type . '_upload_size']) {
                 $pass_the_upload = $lang['upload_too_large'] . '<br />' . $lang['failed_max_filesize'] . ' ' . $config['max_' . $type . '_upload_size'] . '' . $lang['bytes'];
             }
             // check width & height
             $imagedata = GetImageSize("{$filename}");
             $imagewidth = $imagedata[0];
             $imageheight = $imagedata[1];
             if ($config['resize_img'] == '1' && $type != 'vtour') {
                 $max_width = $config['max_' . $type . '_upload_width'];
                 $max_height = $config['max_' . $type . '_upload_height'];
                 $resize_by = $config['resize_by'];
                 $shrinkage = 1;
                 // Figure out what the sizes are going to be AFTER resizing the images to know if we should allow the upload or not
                 if ($resize_by == 'width') {
                     if ($imagewidth > $max_width) {
                         $shrinkage = $imagewidth / $max_width;
                     }
                     $new_img_width = $max_width;
                     $new_img_height = round($imageheight / $shrinkage);
                     if ($new_img_height > $max_height) {
                         $pass_the_upload = $lang['upload_too_high'] . '<br />' . $lang['failed_max_height'] . ' ' . $max_height . '' . $lang['pixels'];
                     }
                 } elseif ($resize_by == 'height') {
                     if ($imageheight > $max_height) {
                         $shrinkage = $imageheight / $max_height;
                     }
                     $new_img_height = $max_height;
                     $new_img_width = round($imagewidth / $shrinkage);
                     if ($new_img_width > $max_width) {
                         $pass_the_upload = $lang['upload_too_wide'] . '<br />' . $lang['failed_max_width'] . ' ' . $max_width . '' . $lang['pixels'];
                     }
                 } elseif ($resize_by == 'both') {
                 } elseif ($resize_by == 'bestfit') {
                 }
             } else {
                 if ($imagewidth > $config['max_' . $type . '_upload_width']) {
                     $pass_the_upload = $lang['upload_too_wide'] . '<br />' . $lang['failed_max_width'] . ' ' . $max_width . '' . $lang['pixels'];
                 }
                 if ($type != 'vtour') {
                     if ($imageheight > $config['max_' . $type . '_upload_height']) {
                         $pass_the_upload = $lang['upload_too_high'] . '<br />' . $lang['failed_max_height'] . ' ' . $max_height . '' . $lang['pixels'];
                     }
                 }
             }
             // security error
             if (strstr($_FILES['userfile']['name'][$file_x], "..") != "") {
                 $pass_the_upload = "{$lang['upload_security_violation']}!";
             }
             // make sure the file hasn't already been uploaded...
             if ($type == "listings") {
                 $save_name = "{$_POST['edit']}" . "_" . "{$realname}";
                 $sql = "SELECT listingsimages_file_name FROM " . $config['table_prefix'] . "listingsimages WHERE listingsimages_file_name = '{$save_name}'";
             } elseif ($type == "vtour") {
                 $save_name = "{$_POST['edit']}" . "_" . "{$realname}";
                 $sql = "SELECT vtourimages_file_name FROM " . $config['table_prefix'] . "vtourimages WHERE vtourimages_file_name = '{$save_name}'";
             } elseif ($type == "user") {
                 $save_name = "{$owner}" . "_" . "{$realname}";
                 $sql = "SELECT userimages_file_name FROM " . $config['table_prefix'] . "userimages WHERE userimages_file_name = '{$save_name}'";
             }
             $recordSet = $conn->Execute($sql);
             if ($recordSet === false) {
                 $misc->log_error($sql);
//.........这里部分代码省略.........
开发者ID:schappaughc,项目名称:iitmapas,代码行数:101,代码来源:images.inc.php

示例2: uploadfile

 function uploadfile($type, $edit, $owner)
 {
     // deals with incoming uploads
     global $config, $conn, $lang;
     require_once $config['basepath'] . '/include/misc.inc.php';
     $misc = new misc();
     $display = '';
     $file_x = 0;
     if ($type == 'users') {
         $sql = "SELECT count(" . $type . "files_id) as num_files FROM " . $config['table_prefix'] . "" . $type . "files WHERE (userdb_id = {$owner})";
     } else {
         $sql = "SELECT count(" . $type . "files_id) as num_files FROM " . $config['table_prefix'] . "" . $type . "files WHERE (listingsdb_id = {$edit})";
     }
     $recordSet = $conn->Execute($sql);
     if ($recordSet === false) {
         $misc->log_error($sql);
     }
     $num_files = $recordSet->fields['num_files'];
     $avaliable_files = $config['max_' . $type . '_file_uploads'] - $num_files;
     while ($file_x < $avaliable_files) {
         if (is_uploaded_file($_FILES['userfile']['tmp_name'][$file_x])) {
             $realname = $misc->clean_filename($_FILES['userfile']['name'][$file_x]);
             $filename = $_FILES['userfile']['tmp_name'][$file_x];
             $extension = substr(strrchr($realname, "."), 1);
             $pass_the_upload = "true";
             // check file extensions
             if (!in_array($extension, explode(',', $config['allowed_file_upload_extensions']))) {
                 $pass_the_upload = "{$lang['upload_invalid_extension']}: {$extension}";
             }
             // check size
             $filesize = $_FILES['userfile']['size'][$file_x];
             if ($config['max_' . $type . '_file_upload_size'] != 0 && $filesize > $config['max_' . $type . '_file_upload_size']) {
                 $pass_the_upload = $lang['upload_too_large'] . '<br />' . $lang['failed_max_filesize'] . ' ' . $config['max_' . $type . '_file_upload_size'] . '' . $lang['bytes'];
             }
             // security error
             if (strstr($_FILES['userfile']['name'][$file_x], "..") != "") {
                 $pass_the_upload = "{$lang['upload_security_violation']}!";
             }
             // make sure the file hasn't already been uploaded...
             if ($type == "listings") {
                 $save_name = $realname;
                 $sql = "SELECT listingsfiles_file_name FROM " . $config['table_prefix'] . "listingsfiles WHERE listingsfiles_file_name = '{$save_name}' AND listingsdb_id = {$_POST['edit']}";
             } elseif ($type == "users") {
                 $save_name = $realname;
                 $sql = "SELECT usersfiles_file_name FROM " . $config['table_prefix'] . "usersfiles WHERE usersfiles_file_name = '{$save_name}'";
             }
             $recordSet = $conn->Execute($sql);
             if ($recordSet === false) {
                 $misc->log_error($sql);
             }
             $num = $recordSet->RecordCount();
             if ($num > 0) {
                 $pass_the_upload = "{$lang['file_exists']}!";
             }
             // IF the upload has passed all the tests do:
             if ($pass_the_upload == "true") {
                 if ($type == "listings") {
                     $uploadpath = $config[listings_file_upload_path] . '/' . $edit;
                     if (!file_exists($uploadpath)) {
                         mkdir($uploadpath, 0777);
                     }
                     move_uploaded_file($_FILES['userfile']['tmp_name'][$file_x], "{$uploadpath}/{$save_name}");
                     // Get Max Image Rank
                     $sql = "SELECT MAX(listingsfiles_rank) AS max_rank FROM " . $config['table_prefix'] . "listingsfiles WHERE (listingsdb_id = '{$edit}')";
                     $recordSet = $conn->Execute($sql);
                     if ($recordSet === false) {
                         $misc->log_error($sql);
                     }
                     $rank = $recordSet->fields['max_rank'];
                     $rank++;
                     $sql = "INSERT INTO " . $config['table_prefix'] . "listingsfiles (listingsdb_id, userdb_id, listingsfiles_file_name, listingsfiles_rank, listingsfiles_caption, listingsfiles_description, listingsfiles_active) VALUES ('{$edit}', '{$owner}', '{$save_name}', {$rank},'','','yes')";
                     $recordSet = $conn->Execute($sql);
                     if ($recordSet === false) {
                         $misc->log_error($sql);
                     }
                     $misc->log_action("{$lang['log_uploaded_listing_file']} {$save_name}");
                     @chmod("{$uploadpath}/{$save_name}", 0777);
                 }
                 // end if $type == "listings"
                 // IF the type of upload is a user file do:
                 if ($type == "users") {
                     $uploadpath = $config[users_file_upload_path] . '/' . $owner;
                     if (!file_exists($uploadpath)) {
                         mkdir($uploadpath, 0777);
                     }
                     move_uploaded_file($_FILES['userfile']['tmp_name'][$file_x], "{$uploadpath}/{$save_name}");
                     // Get Max Image Rank
                     $sql = "SELECT MAX(usersfiles_rank) AS max_rank FROM " . $config['table_prefix'] . "usersfiles WHERE (userdb_id = '{$owner}')";
                     $recordSet = $conn->Execute($sql);
                     if ($recordSet === false) {
                         $misc->log_error($sql);
                     }
                     $rank = $recordSet->fields['max_rank'];
                     $rank++;
                     $sql = "INSERT INTO " . $config['table_prefix'] . "usersfiles (userdb_id, usersfiles_file_name,usersfiles_rank,usersfiles_caption,usersfiles_description,usersfiles_active) VALUES ('{$owner}', '{$save_name}', {$rank},'','','yes')";
                     $recordSet = $conn->Execute($sql);
                     if ($recordSet === false) {
                         $misc->log_error($sql);
                     }
                     $misc->log_action("{$lang['log_uploaded_user_image']} {$save_name}");
//.........这里部分代码省略.........
开发者ID:josegonzalez,项目名称:php-openrealty,代码行数:101,代码来源:files.inc.php


注:本文中的misc::clean_filename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。