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


PHP get_mime函数代码示例

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


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

示例1: file

 public function file($str = '')
 {
     $this->load->library('EncryptionX', array(), 'encryption');
     $this->encryption->key($this->config->item('encryption_key', 'app'));
     $expiryDate = date('D, d M Y H:i:s e', time() + 3600 * 24 * 30);
     header('Cache-Control: max-age=86400');
     header('Expires: ' . $expiryDate);
     $nstr = explode('||', $this->encryption->decode(base64url_decode($str)));
     if (count($nstr) != 5) {
         return show_404();
     }
     $size = $nstr[1] . 'x' . $nstr[2];
     $type = $nstr[3];
     $global = round($nstr[4]);
     $arrf = explode('/', $nstr[0]);
     if (count($arrf) != 3) {
         return show_404();
     }
     $year = $arrf[0];
     $month = $arrf[1];
     $file = $arrf[2];
     $this->load->config('app', TRUE);
     $folder = $this->config->item('uploads-global', 'app');
     if (!$global || !$folder) {
         $folder = $this->config->item('uploads', 'app');
     }
     $date_y = date('Y/m/d', strtotime("-1 day"));
     $filef = "{$folder}thumbs/{$date_y}/{$size}-{$file}";
     $version = $this->config->item('upload-version', 'app') . '.' . date('H');
     $mime = get_mime($filef);
     if ($mime) {
         header("Content-Type: {$mime}");
         readfile($filef);
         exit;
     }
     $date = date('Y/m/d');
     $filef = "{$folder}thumbs/{$date}/{$size}-{$file}";
     $mime = get_mime($filef);
     if ($mime) {
         header("Content-Type: {$mime}");
         readfile($filef);
         exit;
     }
     $thumbFolder = "{$folder}thumbs/{$date}/";
     if (!is_dir($thumbFolder)) {
         mkdir($thumbFolder, 0777, true);
     }
     $this->load->library('image');
     $fileb = "{$folder}{$year}/{$month}/{$file}";
     if (!file_exists($fileb)) {
         return show_404();
     }
     @unlink("{$folder}thumbs/{$date}/{$size}-{$file}");
     $function = $type == 'thumb' ? 'resize' : 'resize_crop';
     $this->image->load($fileb)->set_jpeg_quality(100)->{$function}($nstr[1], $nstr[2])->save("{$folder}thumbs/{$date}/{$size}-{$file}")->clear();
     $mime = get_mime($filef);
     header("Content-Type: {$mime}");
     readfile($filef);
     exit;
 }
开发者ID:juanazareno,项目名称:piscis,代码行数:60,代码来源:FilesP.php

示例2: mail

 /**
  * 快捷发送一封邮件
  * @param string $to 收件人
  * @param string $sub 邮件主题
  * @param string $msg 邮件内容(HTML)
  * @param array $att 附件,每个键为文件名称,值为附件内容(可以为二进制文件),例如array('a.txt' => 'abcd' , 'b.png' => file_get_contents('x.png'))
  * @return bool 成功:true 失败:错误消息
  */
 public static function mail($to, $sub = '无主题', $msg = '无内容', $att = array())
 {
     if (defined("SAE_MYSQL_DB") && class_exists('SaeMail')) {
         $mail = new SaeMail();
         $options = array('from' => option::get('mail_name'), 'to' => $to, 'smtp_host' => option::get('mail_host'), 'smtp_port' => option::get('mail_port'), 'smtp_username' => option::get('mail_smtpname'), 'smtp_password' => option::get('mail_smtppw'), 'subject' => $sub, 'content' => $msg, 'content_type' => 'HTML');
         $mail->setOpt($options);
         $ret = $mail->send();
         if ($ret === false) {
             return 'Mail Send Error: #' . $mail->errno() . ' - ' . $mail->errmsg();
         } else {
             return true;
         }
     } else {
         $From = option::get('mail_name');
         if (option::get('mail_mode') == 'SMTP') {
             $Host = option::get('mail_host');
             $Port = intval(option::get('mail_port'));
             $SMTPAuth = (bool) option::get('mail_auth');
             $Username = option::get('mail_smtpname');
             $Password = option::get('mail_smtppw');
             $Nickname = option::get('mail_yourname');
             if (option::get('mail_ssl') == '1') {
                 $SSL = true;
             } else {
                 $SSL = false;
             }
             $mail = new SMTP($Host, $Port, $SMTPAuth, $Username, $Password, $SSL);
             $mail->att = $att;
             if ($mail->send($to, $From, $sub, $msg, $Nickname)) {
                 return true;
             } else {
                 return $mail->log;
             }
         } else {
             $name = option::get('mail_yourname');
             $mail = new PHPMailer();
             $mail->setFrom($From, $name);
             $mail->addAddress($to);
             $mail->Subject = $sub;
             $mail->msgHTML($msg);
             $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
             foreach ($att as $n => $d) {
                 $mail->addStringAttachment($d, "=?UTF-8?B?" . base64_encode($n) . "?=", 'base64', get_mime(get_extname($n)));
             }
             if (!$mail->send()) {
                 return $mail->ErrorInfo;
             } else {
                 return true;
             }
         }
     }
 }
开发者ID:a1262344305,项目名称:OpenShift-Tieba-Cloud-Sign,代码行数:60,代码来源:class.misc.php

示例3: getMediaFile

 /**
  * Retrieves media file and info from either a URL or localpath
  *
  * @param string  $filepath     The URL or path to the mediafile you wish to send
  * @param integer $maxsizebytes The maximum size in bytes the media file can be. Default 5MB
  *
  * @return bool  false if file information can not be obtained.
  */
 protected function getMediaFile($filepath, $maxsizebytes = 5242880)
 {
     if (filter_var($filepath, FILTER_VALIDATE_URL) !== false) {
         $this->mediaFileInfo = array();
         $this->mediaFileInfo['url'] = $filepath;
         $media = file_get_contents($filepath);
         $this->mediaFileInfo['filesize'] = strlen($media);
         if ($this->mediaFileInfo['filesize'] < $maxsizebytes) {
             $this->mediaFileInfo['filepath'] = tempnam(__DIR__ . DIRECTORY_SEPARATOR . Constants::DATA_FOLDER . DIRECTORY_SEPARATOR . Constants::MEDIA_FOLDER, 'WHA');
             file_put_contents($this->mediaFileInfo['filepath'], $media);
             $this->mediaFileInfo['filemimetype'] = get_mime($this->mediaFileInfo['filepath']);
             $this->mediaFileInfo['fileextension'] = getExtensionFromMime($this->mediaFileInfo['filemimetype']);
             return true;
         } else {
             return false;
         }
     } else {
         if (file_exists($filepath)) {
             //Local file
             $this->mediaFileInfo['filesize'] = filesize($filepath);
             if ($this->mediaFileInfo['filesize'] < $maxsizebytes) {
                 $this->mediaFileInfo['filepath'] = $filepath;
                 $this->mediaFileInfo['fileextension'] = pathinfo($filepath, PATHINFO_EXTENSION);
                 $this->mediaFileInfo['filemimetype'] = get_mime($filepath);
                 return true;
             } else {
                 return false;
             }
         }
     }
     return false;
 }
开发者ID:rezanadimi72,项目名称:Chat-API,代码行数:40,代码来源:whatsprot.class.php

示例4: getMediaFile

 /**
  * Retrieves media file and info from either a URL or localpath
  *
  * @param string  $filepath     The URL or path to the mediafile you wish to send
  * @param integer $maxsizebytes The maximum size in bytes the media file can be. Default 1MB
  *
  * @return bool  false if file information can not be obtained.
  */
 protected function getMediaFile($filepath, $maxsizebytes = 1048576)
 {
     if (filter_var($filepath, FILTER_VALIDATE_URL) !== false) {
         $this->mediaFileInfo = array();
         $this->mediaFileInfo['url'] = $filepath;
         //File is a URL. Create a curl connection but DON'T download the body content
         //because we want to see if file is too big.
         $curl = curl_init();
         curl_setopt($curl, CURLOPT_URL, "{$filepath}");
         curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11");
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($curl, CURLOPT_HEADER, false);
         curl_setopt($curl, CURLOPT_NOBODY, true);
         if (curl_exec($curl) === false) {
             return false;
         }
         //While we're here, get mime type and filesize and extension
         $info = curl_getinfo($curl);
         $this->mediaFileInfo['filesize'] = $info['download_content_length'];
         $this->mediaFileInfo['filemimetype'] = $info['content_type'];
         $this->mediaFileInfo['fileextension'] = pathinfo(parse_url($this->mediaFileInfo['url'], PHP_URL_PATH), PATHINFO_EXTENSION);
         //Only download file if it's not too big
         //TODO check what max file size whatsapp server accepts.
         if ($this->mediaFileInfo['filesize'] < $maxsizebytes) {
             //Create temp file in media folder. Media folder must be writable!
             $this->mediaFileInfo['filepath'] = tempnam(getcwd() . '/' . static::MEDIA_FOLDER, 'WHA');
             $fp = fopen($this->mediaFileInfo['filepath'], 'w');
             if ($fp) {
                 curl_setopt($curl, CURLOPT_NOBODY, false);
                 curl_setopt($curl, CURLOPT_BUFFERSIZE, 1024);
                 curl_setopt($curl, CURLOPT_FILE, $fp);
                 curl_exec($curl);
                 fclose($fp);
             } else {
                 unlink($this->mediaFileInfo['filepath']);
                 curl_close($curl);
                 return false;
             }
             //Success
             curl_close($curl);
             return true;
         } else {
             //File too big. Don't Download.
             curl_close($curl);
             return false;
         }
     } else {
         if (file_exists($filepath)) {
             //Local file
             $this->mediaFileInfo['filesize'] = filesize($filepath);
             if ($this->mediaFileInfo['filesize'] < $maxsizebytes) {
                 $this->mediaFileInfo['filepath'] = $filepath;
                 $this->mediaFileInfo['fileextension'] = pathinfo($filepath, PATHINFO_EXTENSION);
                 $this->mediaFileInfo['filemimetype'] = get_mime($filepath);
                 return true;
             } else {
                 //File too big
                 return false;
             }
         }
     }
     //Couldn't tell what file was, local or URL.
     return false;
 }
开发者ID:Aldairnatan,项目名称:WhatsAPI-Official,代码行数:72,代码来源:whatsprot.class.php

示例5: info

 public function info($file, $type = null)
 {
     if (!is_dir($this->storagePath)) {
         throw new Exception('Tmp path for media not setting up. Provide one.');
     }
     $media = new stdClass();
     $size = $this->getMaxMediaSizeAllowed($type);
     if (filter_var($file, FILTER_VALIDATE_URL) !== false) {
         $media->url = $file;
         //File is a URL. Create a curl connection but DON'T download the body content
         //because we want to see if file is too big.
         $curl = curl_init();
         curl_setopt($curl, CURLOPT_URL, $file);
         curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11');
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($curl, CURLOPT_HEADER, false);
         curl_setopt($curl, CURLOPT_NOBODY, true);
         if (curl_exec($curl) === false) {
             throw new Exception('File ' . $file . ' can\'t be downloaded.');
         }
         //While we're here, get mime type and filesize and extension
         $info = curl_getinfo($curl);
         $media->filesize = $info['download_content_length'];
         $media->filemimetype = $info['content_type'];
         $media->fileextension = pathinfo(parse_url($media->url, PHP_URL_PATH), PATHINFO_EXTENSION);
         //Only download file if it's not too big
         //TODO check what max file size whatsapp server accepts.
         if ($media->filesize < $size) {
             //Create temp file in media folder. Media folder must be writable!
             $media->file = $this->storagePath . 'tmp/' . 'WHA-' . str_replace('.', '', microtime(true)) . '-' . substr(md5(rand()), 0, 6) . '.' . $media->fileextension;
             $fp = fopen($media->file, 'w');
             if ($fp) {
                 curl_setopt($curl, CURLOPT_NOBODY, false);
                 curl_setopt($curl, CURLOPT_BUFFERSIZE, 1024);
                 curl_setopt($curl, CURLOPT_FILE, $fp);
                 curl_exec($curl);
                 fclose($fp);
             }
             //Success
             curl_close($curl);
             return $media;
         } else {
             //File too big. Don't Download.
             curl_close($curl);
             throw new Exception('File ' . $file . ' too big. Don\'t Download.');
         }
     } else {
         if (file_exists($file)) {
             //Local file
             $media->filesize = filesize($file);
             if ($media->filesize < $size) {
                 $media->file = $file;
                 $media->fileextension = pathinfo($file, PATHINFO_EXTENSION);
                 $media->filemimetype = get_mime($file);
                 return $media;
             } else {
                 //File too big
                 throw new Exception('Local File ' . $file . ' too big');
             }
         }
     }
     //Couldn't tell what file was, local or URL.
     throw new Exception('Couldn\'t tell what file was, local or URL');
 }
开发者ID:maikealame,项目名称:whatsapi,代码行数:64,代码来源:Media.php

示例6: api_get_temp_file

/**
 *	Get a file from a temporary (working) repository
 *	@param $param[1] temporary repository
 *	@param $param[2] filename
 *	@param $param['format'] "download", "json" or "raw" (default)
 */
function api_get_temp_file($param = array())
{
    $temp = $param[1];
    $fn = $param[2];
    if (strpos($fn, '../') !== false) {
        // thwart possible attempts to get to files outside of the content directory
        router_error_400('Illegal filename ' . $fn . ' for ' . $temp);
    } else {
        $path = tmp_dir($temp) . '/' . $fn;
    }
    if (!@is_file($path)) {
        router_error_404('Cannot get file ' . $fn . ' in ' . $temp);
    }
    if (isset($param['format'])) {
        $format = $param['format'];
    } else {
        $format = 'raw';
    }
    if ($format === 'download') {
        // force browser to download
        @header('Content-Type: application/octet-stream');
        @header('Content-Disposition: attachment; filename="' . basename($fn) . '"');
        @header('Content-Length: ' . @filesize($path));
        @readfile($path);
        die;
    } else {
        if ($format === 'json') {
            // serve base64-encoded
            return array('fn' => $fn, 'mime' => get_mime($path), 'data' => base64_encode(@file_get_contents($path)));
        } else {
            if ($format === 'raw') {
                // serve with proper MIME type
                $mime = get_mime($path);
                @header('Content-Type: ' . $mime);
                @header('Content-Length: ' . @filesize($path));
                // HACK: add a <base> element to the <head> of any HTML page passing through
                // XXX (later): make this configurable via a $param
                if ($mime !== 'text/html') {
                    @readfile($path);
                } else {
                    $html = @file_get_contents($path);
                    // XXX (later): use mod_rewrite instead of linking to the content dir directly (api.php?... does not work)
                    $base = base_url() . tmp_dir($temp) . '/';
                    $html = str_replace('<head>', '<head>' . "\n" . '<base href="' . $base . '"></base>', $html);
                    echo $html;
                }
                die;
            } else {
                router_error_400('Unsupported format ' . $format);
            }
        }
    }
}
开发者ID:gohai,项目名称:sausagemachine,代码行数:59,代码来源:api.php

示例7: load_work

function load_work($name, $resolve_references = true)
{
    $s = @file_get_contents(content_dir() . '/' . $name . '/meta.txt');
    if ($s === false) {
        return false;
    }
    $work = @json_decode($s, true);
    if (is_null($work)) {
        // be vocal about error
        echo 'Error decoding ' . $name . '/meta.txt';
        if (function_exists(json_last_error_msg())) {
            echo ': ' . json_last_error_msg();
        }
        echo '. Try validating the file with http://jsonlint.com/.';
        exit(1);
    } else {
        if (!is_array($work)) {
            echo 'Error decoding ' . $name . '/meta.txt: Not an object.';
            exit(2);
        }
    }
    /* set name */
    $work['name'] = $name;
    /* set description */
    $s = @file_get_contents(content_dir() . '/' . $name . '/description.html');
    if ($s !== false) {
        $work['description'] = $s;
    } else {
        $work['description'] = '';
    }
    /* normalize all other fields */
    $work = normalize_work($work, $resolve_references);
    // XXX: not necessary for !resolve_references
    $media = load_media($name);
    if ($media !== false) {
        $work['media'] = $media;
    } else {
        $work['media'] = array();
    }
    // XXX: as above
    $work['primary_representation'] = null;
    $fns = @scandir(content_dir() . '/' . $name);
    foreach ($fns as $fn) {
        if (in_array($fn, array('.', '..', 'description.html', 'meta.txt'))) {
            continue;
        }
        if (substr($fn, 0, 1) === '_') {
            continue;
        }
        if (!@is_file(content_dir() . '/' . $name . '/' . $fn)) {
            // not a file
            continue;
        }
        $full_fn = $name . '/' . $fn;
        // check mime type
        $mime = get_mime(content_dir() . '/' . $full_fn);
        if (!in_array(explode('/', $mime)[0], array('image', 'video'))) {
            // only accept images and videos
            continue;
        }
        $media = array('url' => 'JODI/' . $full_fn, 'fn' => $fn, 'description' => '', 'mime' => get_mime(content_dir() . '/' . $full_fn));
        // load image dimensions
        if (explode('/', $media['mime'])[0] === 'image') {
            $media = array_merge($media, get_image_size(content_dir() . '/' . $full_fn));
        }
        $work['primary_representation'] = $media;
    }
    return $work;
}
开发者ID:gohai,项目名称:jms,代码行数:69,代码来源:jms.inc.php

示例8: ws_images_addRemote

function ws_images_addRemote($params, &$service)
{
    global $conf;
    if (!is_admin()) {
        return new PwgError(401, 'Access denied');
    }
    load_language('plugin.lang', URLUPLOADER_PATH);
    $params = array_map('trim', $params);
    $allowed_extensions = array('jpg', 'jpeg', 'png', 'gif');
    $allowed_mimes = array('image/jpeg', 'image/png', 'image/gif');
    // check empty url
    if (empty($params['file_url'])) {
        return new PwgError(WS_ERR_INVALID_PARAM, l10n('File URL is empty'));
    }
    // check remote url
    if (!url_is_remote($params['file_url'])) {
        return new PwgError(WS_ERR_INVALID_PARAM, l10n('Invalid file URL'));
    }
    // check file extension
    if (!in_array(strtolower(get_extension($params['file_url'])), $allowed_extensions)) {
        return new PwgError(WS_ERR_INVALID_PARAM, l10n('Invalid file type'));
    }
    // download file
    include_once PHPWG_ROOT_PATH . 'admin/include/functions.php';
    $temp_filename = $conf['data_location'] . basename($params['file_url']);
    $file = fopen($temp_filename, 'w+');
    $result = fetchRemote($params['file_url'], $file);
    fclose($file);
    // download failed ?
    if (!$result) {
        @unlink($temp_filename);
        return new PwgError(WS_ERR_INVALID_PARAM, l10n('Unable to download file'));
    }
    // check mime-type
    if (!in_array(get_mime($temp_filename, $allowed_mimes[0]), $allowed_mimes)) {
        @unlink($temp_filename);
        return new PwgError(WS_ERR_INVALID_PARAM, l10n('Invalid file type'));
    }
    // add photo
    include_once PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php';
    $image_id = add_uploaded_file($temp_filename, basename($temp_filename), array($params['category']), $params['level']);
    $updates = array();
    if (!empty($params['name'])) {
        $updates['name'] = $params['name'];
    }
    if ($params['url_in_comment'] == 'true') {
        $url = parse_url($params['file_url']);
        $url = $url['scheme'] . '://' . $url['host'];
        $updates['comment'] = '<a href="' . $url . '">' . $url . '</a>';
    }
    single_update(IMAGES_TABLE, $updates, array('id' => $image_id));
    // return infos
    $query = '
SELECT id, name, permalink
  FROM ' . CATEGORIES_TABLE . '
  WHERE id = ' . $params['category'] . '
;';
    $category = pwg_db_fetch_assoc(pwg_query($query));
    $url_params = array('image_id' => $image_id, 'section' => 'categories', 'category' => $category);
    $query = '
SELECT id, path, name
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $image_id . '
;';
    $image_infos = pwg_db_fetch_assoc(pwg_query($query));
    $query = '
SELECT
    COUNT(*) AS nb_photos
  FROM ' . IMAGE_CATEGORY_TABLE . '
  WHERE category_id = ' . $params['category'] . '
;';
    $category_infos = pwg_db_fetch_assoc(pwg_query($query));
    $category_name = get_cat_display_name_from_id($params['category'], null);
    return array('image_id' => $image_id, 'url' => make_picture_url($url_params), 'src' => DerivativeImage::thumb_url($image_infos), 'name' => $image_infos['name'], 'category' => array('id' => $params['category'], 'nb_photos' => $category_infos['nb_photos'], 'label' => $category_name));
}
开发者ID:skylogic004,项目名称:Piwigo-URL-Uploader,代码行数:75,代码来源:ws_functions.inc.php

示例9: file

 public function file($str = '')
 {
     ini_set('memory_limit', '512M');
     $expiryDate = date('D, d M Y H:i:s e', time() + 3600 * 24 * 30);
     header('Cache-Control: max-age=86400');
     header('Expires: ' . $expiryDate);
     $nstr = explode('||', $this->encryption->decode($str));
     if (count($nstr) != 5) {
         return show_404();
     }
     $size = $nstr[1] . 'x' . $nstr[2];
     $type = $nstr[3];
     $global = round($nstr[4]);
     $arrf = explode('/', $nstr[0]);
     if (count($arrf) != 3) {
         return show_404();
     }
     $year = $arrf[0];
     $month = $arrf[1];
     $file = $arrf[2];
     $fileX = $year . $month . '_' . $file;
     $this->load->config('app', TRUE);
     $folder = $this->config->item('uploads-global', 'app');
     if (!$global || !$folder) {
         $folder = $this->config->item('uploads', 'app');
     }
     $date_y = date('Y/m/d', strtotime("-1 day"));
     $filef = "{$folder}thumbs/{$date_y}/{$size}-{$fileX}";
     $version = $this->config->item('upload-version', 'app') . '.' . date('H');
     $mime = get_mime($filef);
     if ($mime) {
         header("Content-Type: {$mime}");
         readfile($filef);
         exit;
     }
     $date = date('Y/m/d');
     $filef = "{$folder}thumbs/{$date}/{$size}-{$fileX}";
     $mime = get_mime($filef);
     if ($mime) {
         header("Content-Type: {$mime}");
         readfile($filef);
         exit;
     }
     /*@chown("{$folder}thumbs/", 'nobody');
       @system("chown -R nobody {$folder}thumbs");*/
     $thumbFolder = "{$folder}thumbs/{$date}/";
     if (!is_dir($thumbFolder)) {
         $mask = umask(0);
         mkdir($thumbFolder, 0777, true);
         umask($mask);
         chmod("{$folder}thumbs/{$date}", 0777);
         #chown("{$folder}thumbs/{$date}", 'nobody');
     }
     $this->load->library('image');
     $fileb = "{$folder}{$year}/{$month}/{$file}";
     if (!file_exists($fileb)) {
         return show_404();
     }
     @unlink("{$folder}thumbs/{$date}/{$size}-{$fileX}");
     $function = $type == 'thumb' ? 'resize' : 'resize_crop';
     $this->image->load($fileb)->set_jpeg_quality(100)->{$function}($nstr[1], $nstr[2])->save("{$folder}thumbs/{$date}/{$size}-{$fileX}")->clear();
     $mime = get_mime($filef);
     header("Content-Type: {$mime}");
     readfile($filef);
     exit;
 }
开发者ID:juanazareno,项目名称:nz,代码行数:66,代码来源:app.php

示例10: redirect

 public function redirect($type = '')
 {
     if ($type == '7dias-cover') {
         $active = round(date('W'));
         $day = round(date('N'));
         $hour = round(date('H'));
         if ($day == 7 && $hour < 10) {
             $active--;
         }
         $file = "data/uploads/7dias/{$active}.jpg";
         $filePath = ROOTPATH . "data/uploads/7dias/{$active}.jpg";
         if (!file_exists($filePath)) {
             $dir = ROOTPATH . "data/uploads/7dias/";
             $fileT = false;
             $timeT = 0;
             if ($handle = opendir($dir)) {
                 while (($file = readdir($handle)) !== FALSE) {
                     if ($file == '.' || $file == '..') {
                         continue;
                     }
                     $time = filemtime($dir . $file);
                     if ($timeT < $time) {
                         $timeT = $time;
                         $fileT = $file;
                     }
                 }
                 closedir($handle);
             }
             $file = "data/uploads/7dias/{$fileT}";
             $filePath = ROOTPATH . $file;
         }
         $mime = get_mime($filePath);
         header("Content-Type: {$mime}");
         readfile($filePath);
         return;
     }
 }
开发者ID:INFOnews,项目名称:infonews,代码行数:37,代码来源:app.php

示例11: file

 public function file($str = '')
 {
     $nstr = explode('||', $this->encryption->decode($str));
     if (count($nstr) != 4) {
         exit;
     }
     $fileb = $nstr[0];
     $filef = $nstr[0];
     header('Cache-control: max-age=' . 60 * 60 * 24 * 365);
     header('Expires: ' . gmdate(DATE_RFC1123, time() + 60 * 60 * 24 * 365));
     header('Pragma: public');
     session_cache_limiter('none');
     if (base_url() == 'http://localhost/infonews/v3/') {
         if (strpos($filef, "advf/imagenes/") === FALSE) {
             return redirect("http://static.grupo23.com/{$filef}");
         }
         if (!file_exists($filef) || !filesize($filef)) {
             $dir = explode('/', $filef);
             $name = array_pop($dir);
             $dir = FCPATH . implode('/', $dir);
             if (!file_exists($dir)) {
                 mkdir($dir, 0777, true);
             }
             @file_put_contents(FCPATH . $filef, @file_get_contents("http://www.infonews.com/{$filef}"));
         }
     }
     if (strpos($filef, "advf/imagenes/") === FALSE) {
         return redirect("http://static.grupo23.com/{$filef}");
     }
     /*$filef = FCPATH . $filef; 
       if(strpos($filef, "advf/imagenes/") === FALSE)
       {
         if(file_exists($filef) && filesize($filef)) 
         {    
           $mime = get_mime($filef);
           header("Content-Type: {$mime}");
           readfile($filef);
           return;
         }
         return redirect("http://static.grupo23.com/{$filef}");
       }*/
     if (!file_exists($filef) || !filesize($filef)) {
         return redirect("http://static.grupo23.com/{$filef}");
     }
     $size = $nstr[1] . 'x' . $nstr[2];
     $type = $nstr[3];
     $arrf = explode('/', str_replace('advf/imagenes/', '', $nstr[0]));
     if ($arrf[0] == 'editadas') {
         $base = $arrf[0];
         $fileSource = $arrf[1];
         $file = $base . '-' . $fileSource;
     } else {
         $year = $arrf[0];
         $month = $arrf[1];
         $fileSource = $arrf[2];
         $file = $year . '-' . $month . '-' . $fileSource;
     }
     $function = $type == 'thumb' ? 'resize' : 'resize_crop';
     $widthX = $width = $nstr[1];
     $heightX = $height = $nstr[2];
     if ($type == 'thumb') {
         $size = getimagesize($filef);
         $width = $size[0];
         $height = $size[1];
         $max = $widthX;
         if ($heightX > $max) {
             $max = $heightX;
         }
         if ($width != $height) {
             if ($width > $height) {
                 $t_height = $max;
                 $t_width = round($width * $t_height / $height);
             } else {
                 $t_width = $max;
                 $t_height = round($t_width * $height / $width);
             }
         } else {
             $t_width = $t_height = $max;
         }
         $width = $t_width;
         $height = $t_height;
     }
     $size = "{$width}x{$height}";
     $date_y = date('Y/m/d', strtotime("-1 day"));
     $filefT = FCPATH . "thumbs/{$date_y}/{$size}-{$file}";
     $this->load->config('app', TRUE);
     $version = $this->config->item('upload-version', 'app') . '.' . date('H');
     if (file_exists($filefT) && filesize($filefT)) {
         $mime = get_mime($filefT);
         header("Content-Type: {$mime}");
         readfile($filefT);
         return;
     }
     $date = date('Y/m/d');
     $filefT = FCPATH . "thumbs/{$date}/{$size}-{$file}";
     if (file_exists($filefT) && filesize($filefT)) {
         $mime = get_mime($filefT);
         header("Content-Type: {$mime}");
         readfile($filefT);
         return;
//.........这里部分代码省略.........
开发者ID:INFOnews,项目名称:infonews,代码行数:101,代码来源:extra.php

示例12: smtp_sendatt

 private function smtp_sendatt()
 {
     $head = '';
     foreach ($this->att as $n => $v) {
         $head .= "\r\n\r\n" . '--' . $this->part_boundary;
         $head .= "\r\n" . 'Content-Type: ' . get_mime(get_extname($n)) . '; charset="utf-8"; name="' . $n . '"';
         $head .= "\r\n" . 'Content-Disposition: attachment; filename="' . $n . '"';
         $head .= "\r\n" . 'Content-Transfer-Encoding: base64';
         $head .= "\r\n\r\n" . base64_encode($v);
     }
     return fputs($this->sock, $head . "\r\n");
 }
开发者ID:sembrono,项目名称:1,代码行数:12,代码来源:smtp.class.php

示例13: get_data

<?php

require_once "GetMime.php";
function get_data($url)
{
    $ch = curl_init();
    $timeout = 5;
    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);
    return $data;
}
header("Content-disposition: attachment; " . $_GET['fname']);
header("Content-type: " . get_mime($_GET['fname']));
echo get_data($_GET['path']);
开发者ID:platonicvizard,项目名称:printcode,代码行数:17,代码来源:FileItem.php

示例14: __construct

 function __construct($valid_request)
 {
     global $lang, $Login, $dB;
     @session_start();
     // Redirect plain /admin/index.php access
     if (preg_match('/index\\.php/', $_SERVER['REQUEST_URI'])) {
         $this->redirect($this->base_redirection($this->root_url), 301);
     }
     $admin_request = sanitize_path(str_replace(sanitize_path(__CHV_FOLDER_ADMIN__), "", str_replace(sanitize_path(__CHV_RELATIVE_ROOT__) . '/', "", $valid_request)));
     // json?blabla instead of (folder?)/admin/json?blabla
     $this->request_array = explode('/', $admin_request);
     $request_file = str_replace('//', '/', __CHV_ROOT_DIR__ . str_replace(__CHV_RELATIVE_ROOT__ == '/' ? '' : __CHV_RELATIVE_ROOT__, '', $_SERVER['REQUEST_URI']));
     // Serve the static file or call the handler?
     if (file_exists($request_file) and !is_dir($request_file) and !preg_match('/php/', get_mime($request_file)) and trim($_SERVER['REQUEST_URI'], '/') !== trim(dirname($_SERVER['SCRIPT_NAME']), '/')) {
         error_reporting(0);
         header('Content-Type: ' . get_mime($request_file) . '; Cache-Control: no-cache; Pragma: no-cache');
         die(readfile($request_file));
     }
     // Now, deny all direct access to the other resources
     if ((file_exists($request_file) or is_dir($request_file)) and trim($_SERVER['REQUEST_URI'], '/') !== trim(dirname($_SERVER['SCRIPT_NAME']), '/') and !$Login->is_admin()) {
         status_header(403);
         die('Forbidden');
     }
     // Organize the source request
     $request_array_explode = explode('?', $this->request_array[0]);
     $request_base = $request_array_explode[0];
     // Now, lets do sub request according to the base request
     switch ($request_base) {
         case '':
             break;
             // admin main
         // admin main
         case 'json':
             json_prepare();
             // Do a special trick for the json action=login
             if ($_REQUEST['action'] !== 'login' and !is_admin()) {
                 $json_array = array('status_code' => 401, 'status_txt' => 'unauthorized');
             } elseif ($_REQUEST['action'] == 'login') {
                 // Check for admin match...
                 $login_user = login_user($_REQUEST['password'], $_REQUEST['keep']);
                 if ($login_user == 'admin') {
                     $json_array = array('status_code' => 200, 'status_txt' => 'logged in');
                 } else {
                     $json_array = array('status_code' => 403, 'status_txt' => 'invalid login');
                 }
             } elseif ($_REQUEST['action'] == 'logout') {
                 do_logout();
                 $json_array = array('status_code' => 200, 'status_txt' => 'logged out');
             } elseif ($_REQUEST['action'] == 'filelist') {
                 require_once __CHV_PATH_CLASSES__ . 'class.filelist.php';
                 $filelist = new FileList($_REQUEST['type'], $_REQUEST['sort'], $_REQUEST['limit'], $_REQUEST['keyword']);
                 $json_array = $filelist->filelist;
             } elseif ($_REQUEST['action'] == 'uploaded') {
                 // In some point there will be a stats class that will help us to output all the stats. This is just the number of uploaded files now.
                 $json_array = array('total' => total_images_uploaded());
                 // The rest of the actions are for the manage class (delete|rename|resize)
             } else {
                 require_once __CHV_PATH_ADMIN_CLASSES__ . 'class.manage.php';
                 $manage = new Manage($_REQUEST);
                 if ($manage->dead) {
                     $json_array = array('status_code' => 403, 'status_txt' => $manage->error);
                 } else {
                     $json_array = $manage->process();
                 }
             }
             $json_array = check_value($json_array) ? $json_array : array('status_code' => 403, 'status_txt' => 'empty json');
             die(json_output($json_array));
             break;
             // json
         // json
         default:
             if (is_admin()) {
                 status_header(404);
                 die('Not found');
             } else {
                 status_header(403);
                 die('Forbidden');
             }
             break;
     }
     // Send the OK status header
     status_header(200);
     if (!is_admin()) {
         $doctitle = get_lang_txt('txt_enter_password') . ' - Chevereto File Manager';
         require_once __CHV_PATH_SYSTEM__ . 'login.php';
     } else {
         require_once __CHV_PATH_ADMIN_SYSTEM__ . 'header.php';
         require_once __CHV_PATH_ADMIN_SYSTEM__ . 'filemanager.php';
     }
 }
开发者ID:JJaicmkmy,项目名称:Chevereto,代码行数:90,代码来源:class.adminhandler.php


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