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


PHP getFileExtension函数代码示例

本文整理汇总了PHP中getFileExtension函数的典型用法代码示例。如果您正苦于以下问题:PHP getFileExtension函数的具体用法?PHP getFileExtension怎么用?PHP getFileExtension使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: initialize_page

function initialize_page()
{
    $post_action = "";
    if (isset($_POST['submit'])) {
        $post_action = $_POST['submit'];
    }
    if ($post_action == "Add Document" || $post_action == "Add and Return to List") {
        $name = $_POST['name'];
        $file_type = getFileExtension($_FILES['file']['name']);
        $filename = slug(getFileName($_FILES['file']['name']));
        $filename_string = $filename . "." . $file_type;
        // Check to make sure there isn't already a file with that name
        $possibledoc = Documents::FindByFilename($filename_string);
        if (is_object($possibledoc)) {
            setFlash("<h3>Failure: Document filename already exists!</h3>");
            redirect("admin/add_document");
        }
        $target_path = SERVER_DOCUMENTS_ROOT . $filename_string;
        if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
            $new_doc = MyActiveRecord::Create('Documents', array('name' => $name, 'filename' => $filename_string, 'file_type' => $file_type));
            $new_doc->save();
            if (!chmod($target_path, 0644)) {
                setFlash("<h3>Warning: Document Permissions not set; this file may not display properly</h3>");
            }
            setFlash("<h3>Document uploaded</h3>");
        } else {
            setFlash("<h3>Failure: Document could not be uploaded</h3>");
        }
        if ($post_action == "Add and Return to List") {
            redirect("admin/list_documents");
        }
    }
}
开发者ID:highchair,项目名称:hcd-trunk,代码行数:33,代码来源:add_document.php

示例2: _initialize

 /**
  * Initialize the upload class
  * @param string $upload The key value of the $_FILES superglobal to use
  */
 private function _initialize($upload)
 {
     $this->_uploadedFile = $upload['name'];
     $this->_tempName = $upload['tmp_name'];
     $this->_fileSize = $upload['size'];
     $this->_extension = getFileExtension($this->_uploadedFile);
     $this->_mimeType = getFileType($this->_tempName);
 }
开发者ID:ITESolutions,项目名称:desktop,代码行数:12,代码来源:Upload.php

示例3: getDatabaseFileExtension

 /**
  * Get file extension for database resource.
  * @param 	$fileId 	Id of file in database to get extension from.
  */
 function getDatabaseFileExtension($fileId)
 {
     global $dbi;
     $result = $dbi->query("SELECT name FROM " . fileTableName . " WHERE id=" . $dbi->quote($fileId));
     if ($result->rows()) {
         list($fileName) = $result->fetchrow_array();
         return convertToLowercase(getFileExtension($fileName));
     }
     return "";
 }
开发者ID:gkathir15,项目名称:catmis,代码行数:14,代码来源:File.class.php

示例4: getFileName

function getFileName($album, $filename)
{
    global $pic_root;
    $ext = getFileExtension($filename);
    $file_name = str_replace("." . $ext, "", $filename);
    $upload_file_name = $file_name;
    $i = 0;
    while (file_exists($pic_root . $album . "/" . $upload_file_name . "." . $ext)) {
        $upload_file_name = $file_name . "-" . ++$i;
    }
    return $upload_file_name . "." . $ext;
}
开发者ID:Kylemurray25,项目名称:wmlmusicguide,代码行数:12,代码来源:pic_upload.php

示例5: listFilesFromType

function listFilesFromType($folder, $type)
{
    $array = array();
    if ($d = opendir($folder)) {
        while (false !== ($file = readdir($d))) {
            if ($file != '.' && $file != '..' && getFileExtension($file) == $type) {
                $array[] .= $folder . "/" . $file;
            }
        }
    }
    return $array;
}
开发者ID:GrottoCenter,项目名称:GrottoCenter,代码行数:12,代码来源:genScriptJS.php

示例6: show_documents

/**
 * Returns an overview of certain documents
 *
 * @param Array $documents Ids of the documents in question
 * @param mixed $open      Array containing open states of documents
 * @return string Overview of documents as html, ready to be displayed
 */
function show_documents($documents, $open = null)
{
    if (!is_array($documents)) {
        return;
    }
    if (!is_null($open) && !is_array($open)) {
        $open = null;
    }
    if (is_array($open)) {
        reset($open);
        $ank = key($open);
    }
    if (!empty($documents)) {
        $query = "SELECT {$GLOBALS['_fullname_sql']['full']} AS fullname, username, user_id,\n                         dokument_id, filename, filesize, downloads, protected, url, description,\n                         IF(IFNULL(name, '') = '', filename, name) AS t_name,\n                         GREATEST(a.chdate, a.mkdate) AS chdate\n                  FROM dokumente AS a\n                  LEFT JOIN auth_user_md5 USING (user_id)\n                  LEFT JOIN user_info USING (user_id)\n                  WHERE dokument_id IN (?)\n                  ORDER BY a.chdate DESC";
        $statement = DBManager::get()->prepare($query);
        $statement->execute(array($documents));
        $documents = $statement->fetchAll(PDO::FETCH_ASSOC);
    }
    foreach ($documents as $index => $document) {
        $type = empty($document['url']) ? 0 : 6;
        $is_open = is_null($open) || $open[$document['dokument_id']] ? 'open' : 'close';
        $extension = getFileExtension($document['filename']);
        // Create icon
        $icon = sprintf('<a href="%s">%s</a>', GetDownloadLink($document['dokument_id'], $document['filename'], $type), GetFileIcon($extension, true)->asImg());
        // Create open/close link
        $link = $is_open === 'open' ? URLHelper::getLink('#dok_anker', array('close' => $document['dokument_id'])) : URLHelper::getLink('#dok_anker', array('open' => $document['dokument_id']));
        // Create title including filesize and number of downloads
        $size = $document['filesize'] > 1024 * 1024 ? sprintf('%u MB', round($document['filesize'] / 1024 / 1024)) : sprintf('%u kB', round($document['filesize'] / 1024));
        $downloads = $document['downloads'] == 1 ? '1 ' . _('Download') : $document['downloads'] . ' ' . _('Downloads');
        $title = sprintf('<a href="%s"%s class="tree">%s</a> (%s / %s)', $link, $ank == $document['dokument_id'] ? ' name="dok_anker"' : '', htmlReady(mila($document['t_name'])), $size, $downloads);
        // Create additional information
        $addon = sprintf('<a href="%s">%s</a> %s', URLHelper::getLink('dispatch.php/profile', array('username' => $document['username'])), $document['fullname'], date('d.m.Y H:i', $document['chdate']));
        if ($document['protected']) {
            $addon = tooltipicon(_('Diese Datei ist urheberrechtlich geschützt!')) . ' ' . $addon;
        }
        if (!empty($document['url'])) {
            $addon .= ' ' . Icon::create('link-extern', 'clickable', ['title' => _('Diese Datei wird von einem externen Server geladen!')])->asImg(16);
        }
        // Attach created variables to document
        $documents[$index]['addon'] = $addon;
        $documents[$index]['extension'] = $extension;
        $documents[$index]['icon'] = $icon;
        $documents[$index]['is_open'] = $is_open;
        $documents[$index]['link'] = $link;
        $documents[$index]['title'] = $title;
        $documents[$index]['type'] = $type;
    }
    $template = $GLOBALS['template_factory']->open('user_activities/files-details');
    $template->documents = $documents;
    return $template->render();
}
开发者ID:ratbird,项目名称:hope,代码行数:58,代码来源:user_activities.php

示例7: move

function move($path, $filename, $newname = null)
{
    $allowed = array('jpg', 'jpeg', 'pdf', 'png', 'xls', 'xlsx', 'zip');
    if (file_exists($_FILES[$filename]['tmp_name'])) {
        if (in_array(getFileExtension(getFileName($filename)), $allowed) && $_FILES[$filename]['error'] == 0) {
            $uploadname = isset($newname) ? $newname : getFileName($filename);
            try {
                move_uploaded_file($_FILES[$filename]['tmp_name'], $path . $uploadname);
            } catch (Exception $e) {
                echo "Error Occurred Uploading File: " . $e->getMessage();
            }
        }
    } else {
        throw new Exception('FILE NOT FOUND');
    }
}
开发者ID:slim12kg,项目名称:Anastat,代码行数:16,代码来源:file.php

示例8: uploadFiletoDB

function uploadFiletoDB($UserFileName)
{
    $TransactionArray = array();
    $TblName = TableName;
    $FileName = $_FILES[$UserFileName]['name'];
    $FileServerName = $_FILES[$UserFileName]['tmp_name'];
    $CSVFIle = 'transactionTable.csv';
    $CSVDelimiter = ';';
    $ValidRecordswrited = 0;
    $InvalidRecords = 0;
    if (getFileExtension($FileName) == 'xlsx') {
        convertXLStoCSV($FileServerName, $CSVFIle);
        $CSVDelimiter = ',';
    } else {
        $CSVFIle = $FileServerName;
    }
    $TransactionArray = csv_to_array($CSVFIle, $CSVDelimiter);
    if (sizeof($TransactionArray) > 100000) {
        echo '<br>';
        echo "Error - file rows cont is to much";
        return false;
    }
    $Connection = mysql_connect(ServerName, UserName, Password);
    $db_selected = mysql_select_db(DBName, $Connection);
    if (!$Connection) {
        die("Connection failed: " . mysql_error());
    }
    foreach ($TransactionArray as $Line) {
        if (checkTransactionRecord($Line)) {
            $Request = "INSERT INTO {$TblName}(`Account`, `Description`, `CurrencyCode`, `Ammount`) VALUES ('{$Line['Account']}','{$Line['Description']}','{$Line['CurrencyCode']}',{$Line['Amount']})";
            $result = mysql_query($Request);
            if (!$result) {
                echo 'Query error: ' . mysql_error();
            } else {
                $ValidRecordswrited++;
            }
        } else {
            $InvalidRecords++;
        }
    }
    mysql_close($Connection);
    echo '<br> <br>';
    echo "Valid records writed to DataBase: {$ValidRecordswrited}";
    echo '<br>';
    echo "Invalid records count: {$InvalidRecords}";
}
开发者ID:pj-infest,项目名称:ElifTechTask,代码行数:46,代码来源:upload.php

示例9: upload_file

function upload_file($tabla, $type, $archivo, $archivo_name)
{
    $s_ = "select * from configuracion where variable='ruta_cargas'";
    $r_ = mysql_query($s_);
    $d_ = mysql_fetch_array($r_);
    $r_server = $d_['valor'];
    $pext = getFileExtension($archivo_name);
    $nombre = date("YmdHis") . "." . $pext;
    $nom_final = $r_server . $nombre;
    if (is_uploaded_file($archivo)) {
        if (!copy($archivo, "{$nom_final}")) {
            echo "<script>alert('Error al subir el archivo: {$nom_final}');</script>";
            upload_form($tabla);
            exit;
        } else {
            insert_csv($tabla, $type, $nombre);
        }
    }
}
开发者ID:BrutalAndSick,项目名称:scrap,代码行数:19,代码来源:fun_modelos.php

示例10: save_uploaded_file

 function save_uploaded_file($tmp_name, $file_name, $isportimg = false, $isentryimg = false, $maxwidth = 0, $maxheight = 0)
 {
     $filetype = getFileExtension($file_name);
     $file_name = slug(basename($file_name, $filetype));
     $new_file_name = $this->id . "-" . $file_name . '.' . $filetype;
     move_uploaded_file($tmp_name, $this->get_local_image_path($new_file_name));
     chmod($this->get_local_image_path($new_file_name), 0644);
     $max_width = 0;
     $max_height = 0;
     if ($maxwidth != 0) {
         $max_width = $maxwidth;
     } elseif ($maxheight != 0) {
         $max_height = $maxheight;
     } elseif ($isportimg) {
         if (defined("MAX_PORTFOLIO_IMAGE_HEIGHT")) {
             $max_height = MAX_PORTFOLIO_IMAGE_HEIGHT;
         }
         if (defined("MAX_PORTFOLIO_IMAGE_WIDTH")) {
             $max_width = MAX_PORTFOLIO_IMAGE_WIDTH;
         }
     } elseif ($isentryimg) {
         if (defined("MAX_ENTRY_IMAGE_HEIGHT")) {
             $max_height = MAX_ENTRY_IMAGE_HEIGHT;
         }
         if (defined("MAX_ENTRY_IMAGE_WIDTH")) {
             $max_width = MAX_ENTRY_IMAGE_WIDTH;
         }
     } else {
         if (defined("MAX_GALLERY_IMAGE_HEIGHT")) {
             $max_height = MAX_GALLERY_IMAGE_HEIGHT;
         }
         if (defined("MAX_GALLERY_IMAGE_WIDTH")) {
             $max_width = MAX_GALLERY_IMAGE_WIDTH;
         }
     }
     $this->filename = $new_file_name;
     $this->save();
     resizeToMultipleMaxDimensions($this->get_local_image_path($new_file_name), $max_width, $max_height, $filetype);
     //$query = "UPDATE photos SET filename = $file_name WHERE id = {$this->id};";
     //return mysql_query( $query, MyActiveRecord::Connection() ) or die( $query );
 }
开发者ID:highchair,项目名称:hcd-trunk,代码行数:41,代码来源:photos.php

示例11: saveFileTo

function saveFileTo($name, $path, $width = 0, $height = 0)
{
    if (!$_FILES[$name]) {
        return;
    }
    if ($_FILES[$name]["error"] != 0) {
        return;
    }
    $tempFile = $_FILES[$name]['tmp_name'];
    $fileName = $_FILES[$name]['name'];
    //$fileSize = $_FILES['Filedata']['size'];
    if (!is_dir(dirname($path))) {
        mkdir(dirname($path), true);
        chmod(dirname($path), 777);
    }
    if ($width == 0) {
        move_uploaded_file($tempFile, $path);
    } else {
        move_uploaded_file($tempFile, $tempFile . "." . getFileExtension($fileName));
        createImage($tempFile . "." . getFileExtension($fileName), $path, $width, $height);
    }
}
开发者ID:qichangjun,项目名称:HTMLLearn,代码行数:22,代码来源:upload.php

示例12: uploadFile

function uploadFile($file, $path, $allowType, $maxSize)
{
    $fileName = $file['name'];
    $ext = getFileExtension($fileName);
    $fileSize = $file['size'];
    $tmpFile = $file['tmp_name'];
    $result = ["error" => [], "path" => ""];
    if ($fileSize > $maxSize) {
        $result['error'][] = ["msg" => "Exceeded filesize limit (" . $maxSize / 1000000 . "MB)"];
    }
    if (count($result['error']) == 0) {
        $fileName = time() . "_" . $fileName;
        if (!is_dir(getcwd() . $path)) {
            mkdir($path, 0777, true);
        }
        $path = $path . "/" . $fileName;
        if (move_uploaded_file(stmpFile, getcwd() . $path)) {
            $result['path'] = $path;
        } else {
            $result['error'][] = ["msg" => " Error on upload file : Permission denied"];
        }
    }
    return $result;
}
开发者ID:dieucay88,项目名称:dieucay88.github.io,代码行数:24,代码来源:global.php

示例13: getMIMEType

function getMIMEType($ext, $filename = null)
{
    if ($filename) {
        return getMIMEType(getFileExtension($filename));
    } else {
        switch (strtolower($ext)) {
            // Image
            case 'gif':
                return 'image/gif';
            case 'jpeg':
            case 'jpg':
            case 'jpe':
                return 'image/jpeg';
            case 'png':
                return 'image/png';
            case 'tiff':
            case 'tif':
                return 'image/tiff';
            case 'bmp':
                return 'image/bmp';
                // Sound
            // Sound
            case 'wav':
                return 'audio/x-wav';
            case 'mpga':
            case 'mp2':
            case 'mp3':
                return 'audio/mpeg';
            case 'm3u':
                return 'audio/x-mpegurl';
            case 'wma':
                return 'audio/x-msaudio';
            case 'ra':
                return 'audio/x-realaudio';
                // Document
            // Document
            case 'css':
                return 'text/css';
            case 'html':
            case 'htm':
            case 'xhtml':
                return 'text/html';
            case 'rtf':
                return 'text/rtf';
            case 'sgml':
            case 'sgm':
                return 'text/sgml';
            case 'xml':
            case 'xsl':
                return 'text/xml';
            case 'hwp':
            case 'hwpml':
                return 'application/x-hwp';
            case 'pdf':
                return 'application/pdf';
            case 'odt':
            case 'ott':
                return 'application/vnd.oasis.opendocument.text';
            case 'ods':
            case 'ots':
                return 'application/vnd.oasis.opendocument.spreadsheet';
            case 'odp':
            case 'otp':
                return 'application/vnd.oasis.opendocument.presentation';
            case 'sxw':
            case 'stw':
                return '	application/vnd.sun.xml.writer';
            case 'sxc':
            case 'stc':
                return '	application/vnd.sun.xml.calc';
            case 'sxi':
            case 'sti':
                return '	application/vnd.sun.xml.impress';
            case 'doc':
                return 'application/vnd.ms-word';
            case 'xls':
            case 'xla':
            case 'xlt':
            case 'xlb':
                return 'application/vnd.ms-excel';
            case 'ppt':
            case 'ppa':
            case 'pot':
            case 'pps':
                return 'application/vnd.mspowerpoint';
            case 'vsd':
            case 'vss':
            case 'vsw':
                return 'application/vnd.visio';
            case 'docx':
            case 'docm':
            case 'pptx':
            case 'pptm':
            case 'xlsx':
            case 'xlsm':
                return 'application/vnd.openxmlformats';
            case 'csv':
                return 'text/comma-separated-values';
                // Multimedia
            // Multimedia
//.........这里部分代码省略.........
开发者ID:ragi79,项目名称:Textcube,代码行数:101,代码来源:file.php

示例14: while

$outputFiles = '';
while (false !== ($file = readdir($handle))) {
    $previewFile = getPreviewFileFromLive(DIR . '/' . $file);
    if (strstr($file, 'phpthumb') || strstr($file, 'phpthumb') || !file_exists($previewFile)) {
        continue;
    }
    if (!in_array($file, $reserved_filenames)) {
        $itemsFound++;
        if (is_dir(DIR . '/' . $file)) {
            // Directory
            $outputDirs .= "\n<li class=\"dir\">";
            $outputDirs .= '<a href="?dir=' . DIR . '/' . $file . '" title="Browse ' . $file . '">';
            $outputDirs .= $file;
            $outputDirs .= '</a></li>';
        } else {
            if (getFileExtension($file) == 'html' || getFileExtension($file) == 'php') {
                // File
                $outputFiles .= "\n" . '<li class="file"><a href="javascript:selectPage(\'' . DIR . '/' . $file . '\');" >';
                $outputFiles .= $file;
                $outputFiles .= '</a>';
                $outputFiles .= "\n</li>";
            }
        }
    }
}
closedir($handle);
if ($itemsFound > 0) {
    $outputHTML = '<div class="bigLinks"><ul>' . $outputDirs . $outputFiles . '<!-- 3 --></ul></div>';
} else {
    $outputHTML .= '<div><span class="info">No files or folders found</span></div>';
}
开发者ID:chrismunden,项目名称:cmsfromscratch,代码行数:31,代码来源:select-page.php

示例15: guardar_1

function guardar_1($partes, $partes_name, $comentario, $accion_correctiva)
{
    $s_ = "select * from configuracion where variable='ruta_capturas'";
    $r_ = mysql_query($s_);
    $d_ = mysql_fetch_array($r_);
    $r_server = $d_['valor'];
    $pext = getFileExtension($partes_name);
    $nombre_ = "partes_UID" . $_SESSION["IDEMP"] . "." . $pext;
    $nom_final_ = $r_server . $nombre_;
    if (is_uploaded_file($partes)) {
        if (!copy($partes, "{$nom_final_}")) {
            echo "<script>alert('Error al subir el archivo de partes: {$nom_final_}');</script>";
            nuevo($comentario, $accion_correctiva);
            exit;
        }
    }
    insert_csv($nombre_, $comentario, $accion_correctiva);
}
开发者ID:BrutalAndSick,项目名称:scrap,代码行数:18,代码来源:scrap_archivo_35.php


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