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


PHP readfile_chunked函数代码示例

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


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

示例1: satispress_send_file

/**
 * Send a download.
 *
 * @since 0.1.0
 *
 * @param string $file An absolute file path.
 */
function satispress_send_file($file)
{
    @session_write_close();
    if (function_exists('apache_setenv')) {
        @apache_setenv('no-gzip', 1);
    }
    if (get_magic_quotes_runtime()) {
        @set_magic_quotes_runtime(0);
    }
    @ini_set('zlib.output_compression', 'Off');
    @set_time_limit(0);
    @ob_end_clean();
    if (ob_get_level()) {
        @ob_end_clean();
        // Zip corruption fix.
    }
    nocache_headers();
    header('Robots: none');
    header('Content-Type: application/force-download');
    header('Content-Description: File Transfer');
    header('Content-Disposition: attachment; filename="' . basename($file) . '";');
    header('Content-Transfer-Encoding: binary');
    if ($size = @filesize($file)) {
        header('Content-Length: ' . $size);
    }
    @readfile_chunked($file) or wp_die(__('File not found', 'satispress'));
    exit;
}
开发者ID:blazersix,项目名称:satispress,代码行数:35,代码来源:functions.php

示例2: display_error

function display_error()
{
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: no-cache');
    header("Content-Type: image/gif");
    readfile_chunked("./images/read_error48x48.gif");
    exit;
}
开发者ID:phill104,项目名称:branches,代码行数:8,代码来源:picture.php

示例3: get

 function get($task_id)
 {
     $filepath = $this->directory . '/' . $task_id . '.arff';
     if (file_exists($filepath) == false) {
         $this->generate($task_id, $filepath);
     }
     header('Content-type: text/plain');
     header('Content-Length: ' . filesize($filepath));
     readfile_chunked($filepath);
 }
开发者ID:jaksmid,项目名称:website,代码行数:10,代码来源:api_splits.php

示例4: download_file

/**
 * This function does the action of forcing the browser to download the
 * specified file as well as feeds the bits of the file to the browser.
 * 
 * @param string $filePath is the path to the file that we want to download.
 * @return int Error code if one exists.  Return of 0 indicates no error.
 */
function download_file($filePath)
{
    $allowed_ext = array('zip' => 'application/zip', 'pdf' => 'application/pdf', 'doc' => 'application/msword', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'exe' => 'application/octet-stream', 'gif' => 'image/gif', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'mov' => 'video/quicktime', 'avi' => 'video/x-msvideo');
    $toReturn = 0;
    if ($filePath != "" && file_exists($filePath)) {
        $file_extension = strtolower(substr(strrchr($filePath, "."), 1));
        // get mime type of the file.
        $ctype = '';
        if (!array_key_exists($file_extension, $allowed_ext)) {
            // mime type is not set, get from server settings
            if (function_exists('mime_content_type')) {
                $ctype = mime_content_type($file_path);
            } else {
                if (function_exists('finfo_file')) {
                    $finfo = finfo_open(FILEINFO_MIME);
                    // return mime type
                    $ctype = finfo_file($finfo, $file_path);
                    finfo_close($finfo);
                }
            }
            if ($ctype == '') {
                $ctype = "application/force-download";
            }
        } else {
            // get mime type defined by admin
            $ctype = $allowed_ext[$file_extension];
        }
        $oldPath = getcwd();
        // get current working directory
        $filePathArray = getPathArray($filePath);
        changeDirectory($filePathArray);
        $filename = getFilename($filePath);
        // Tell the browser the mime type of the file to be downloaded.
        header('Content-type: ' . $ctype);
        // Tell the browser what to call the file.
        header('Content-Disposition: attachment; filename="' . $filename . '"');
        header("Content-Length: " . filesize($filename));
        ob_clean();
        flush();
        $bytesSent = readfile_chunked($filename);
        $reverseFilePath = array();
        for ($i = 0; $i < count($filePathArray); ++$i) {
            $reverseFilePath[] = "..";
        }
        changeDirectory($reverseFilePath);
        // change back to the original directory
        $toReturn = 0;
        //exit;
    } else {
        $toReturn = 404;
        // file not found
    }
    return $toReturn;
}
开发者ID:hjoelr,项目名称:com_simpledownload,代码行数:61,代码来源:download.php

示例5: download

 function download($id, $name = 'undefined')
 {
     $file = $this->File->getById($id);
     if ($this->_check_rights($file)) {
         if ($file === false || file_exists(DATA_PATH . $file->filepath) === false) {
             $this->_error404();
         } else {
             $this->_header_download($file);
             readfile_chunked(DATA_PATH . $file->filepath);
         }
     }
     // else, an appropriate message is shown.
 }
开发者ID:jaksmid,项目名称:website,代码行数:13,代码来源:data.php

示例6: force_download

 function force_download($filename = '', $file = '')
 {
     if ($filename == '' or $file == '') {
         return FALSE;
     }
     // Try to determine if the filename includes a file extension.
     // We need it in order to set the MIME type
     if (FALSE === strpos($filename, '.')) {
         return FALSE;
     }
     // Grab the file extension
     $x = pathinfo($file);
     $extension = $x["extension"];
     // Load the mime types
     @(include APPPATH . 'config/mimes' . EXT);
     // Set a default mime if we can't find it
     if (!isset($mimes[$extension])) {
         $mime = 'application/octet-stream';
     } else {
         $mime = is_array($mimes[$extension]) ? $mimes[$extension][0] : $mimes[$extension];
     }
     // Read the file size to pass to the
     // headers and also for our chunk method
     $size = filesize($file);
     // Generate the server headers
     if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE) {
         header('Content-Type: "' . $mime . '"');
         header('Content-Disposition: attachment; filename="' . $filename . '"');
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header("Content-Transfer-Encoding: binary");
         header('Pragma: public');
         header("Content-Length: " . $size);
     } else {
         header('Content-Type: "' . $mime . '"');
         header('Content-Disposition: attachment; filename="' . $filename . '"');
         header("Content-Transfer-Encoding: binary");
         header('Expires: 0');
         header('Pragma: no-cache');
         header("Content-Length: " . $size);
     }
     readfile_chunked($file, $size);
     exit;
 }
开发者ID:ebeauchamps,项目名称:brilliantretail,代码行数:44,代码来源:my_download_helper.php

示例7: exit_error

if (!$group || !is_object($group)) {
    exit_error(_('Error'), _('Error creating group'));
} else {
    if ($group->isError()) {
        exit_error(_('Error'), $group->getErrorMessage());
    }
}
// Snapshot can be downloaded only if anon SCM is enabled or if the
// logged in user belongs the group
$permission = $group->enableAnonSCM();
if (session_loggedin()) {
    $perm =& $group->getPermission(session_get_user());
    if ($perm && is_object($perm) && !$perm->isError() && $perm->isMember()) {
        $permission = true;
    }
}
if (!$permission) {
    exit_permission_denied();
}
// Download file
$group_name = $group->getUnixName();
$filename = $group_name . '-scm-latest.tar.gz';
if (file_exists($sys_scm_snapshots_path . '/' . $filename)) {
    Header('Content-disposition: filename="' . str_replace('"', '', $filename) . '"');
    Header('Content-type: application/x-gzip');
    $length = filesize($sys_scm_snapshots_path . '/' . $filename);
    Header('Content-length: ' . $length);
    readfile_chunked($sys_scm_snapshots_path . '/' . $filename);
} else {
    session_redirect(util_make_url('/404.php'));
}
开发者ID:neymanna,项目名称:fusionforge,代码行数:31,代码来源:snapshots.php

示例8: woocommerce_download_product


//.........这里部分代码省略.........
            $remote_file = true;
        } else {
            $remote_file = false;
            $file_path = realpath($file_path);
        }
        // Download the file
        $file_extension = strtolower(substr(strrchr($file_path, "."), 1));
        $ctype = "application/force-download";
        foreach (get_allowed_mime_types() as $mime => $type) {
            $mimes = explode('|', $mime);
            if (in_array($file_extension, $mimes)) {
                $ctype = $type;
                break;
            }
        }
        if ($file_download_method == 'xsendfile') {
            if (getcwd()) {
                // Path fix - kudos to Jason Judge
                $file_path = trim(preg_replace('`^' . getcwd() . '`', '', $file_path), '/');
            }
            header("Content-Disposition: attachment; filename=\"" . basename($file_path) . "\";");
            if (function_exists('apache_get_modules') && in_array('mod_xsendfile', apache_get_modules())) {
                header("X-Sendfile: {$file_path}");
                exit;
            } elseif (stristr(getenv('SERVER_SOFTWARE'), 'lighttpd')) {
                header("X-Lighttpd-Sendfile: {$file_path}");
                exit;
            } elseif (stristr(getenv('SERVER_SOFTWARE'), 'nginx') || stristr(getenv('SERVER_SOFTWARE'), 'cherokee')) {
                header("X-Accel-Redirect: {$file_path}");
                exit;
            }
        }
        /**
         * readfile_chunked
         *
         * Reads file in chunks so big downloads are possible without changing PHP.INI - http://codeigniter.com/wiki/Download_helper_for_large_files/
         *
         * @access   public
         * @param    string    file
         * @param    boolean    return bytes of file
         * @return   void
         */
        if (!function_exists('readfile_chunked')) {
            function readfile_chunked($file, $retbytes = TRUE)
            {
                $chunksize = 1 * (1024 * 1024);
                $buffer = '';
                $cnt = 0;
                $handle = fopen($file, 'r');
                if ($handle === FALSE) {
                    return FALSE;
                }
                while (!feof($handle)) {
                    $buffer = fread($handle, $chunksize);
                    echo $buffer;
                    ob_flush();
                    flush();
                    if ($retbytes) {
                        $cnt += strlen($buffer);
                    }
                }
                $status = fclose($handle);
                if ($retbytes and $status) {
                    return $cnt;
                }
                return $status;
            }
        }
        @session_write_close();
        if (function_exists('apache_setenv')) {
            @apache_setenv('no-gzip', 1);
        }
        @ini_set('zlib.output_compression', 'Off');
        @set_time_limit(0);
        @set_magic_quotes_runtime(0);
        @ob_end_clean();
        if (ob_get_level()) {
            @ob_end_clean();
        }
        // Zip corruption fix
        header("Pragma: no-cache");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Robots: none");
        header("Content-Type: " . $ctype . "");
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=\"" . basename($file_path) . "\";");
        header("Content-Transfer-Encoding: binary");
        if ($size = @filesize($file_path)) {
            header("Content-Length: " . $size);
        }
        // Serve it
        if ($remote_file) {
            @readfile_chunked("{$file_path}") or header('Location: ' . $file_path);
        } else {
            @readfile_chunked("{$file_path}") or wp_die(__('File not found', 'woocommerce') . ' <a href="' . home_url() . '">' . __('Go to homepage &rarr;', 'woocommerce') . '</a>');
        }
        exit;
    }
}
开发者ID:eddiewilson,项目名称:new-ke,代码行数:101,代码来源:woocommerce-functions.php

示例9: header

         header("Robots: none");
         header("Content-Type: " . $ctype . "");
         header("Content-Description: File Transfer");
         header("Content-Transfer-Encoding: binary");
         if (isset($header_filename) && !empty($header_filename)) {
             header("Content-Disposition: " . $header_filename . ";");
         } else {
             if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
                 $iefilename = preg_replace('/\\./', '%2e', $filename, substr_count($filename, '.') - 1);
                 header("Content-Disposition: attachment; filename=\"" . $iefilename . "\";");
             } else {
                 header("Content-Disposition: attachment; filename=\"" . $filename . "\";");
             }
         }
         if (isset($filesize) && $filesize > 0) {
             @readfile_chunked($thefile, $filesize);
         } else {
             readfile($thefile);
         }
         exit;
     } elseif ($isURI && !ini_get('allow_url_fopen')) {
         // O dear, we cannot force the remote file without allow_url_fopen
         @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
         wp_die(__('Forcing the download of externally hosted files is not supported by this server.', "wp-download_monitor"), __('Forcing the download of externally hosted files is not supported by this server.', "wp-download_monitor"));
     }
     // If we have not exited by now, the only thing left to do is die.
     // We cannot download something that is a local file system path on another system, and that's the only thing left it could be!
     @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
     wp_die(__('Download path is invalid!', "wp-download_monitor"), __('Download path is invalid!', "wp-download_monitor"));
 }
 if (!strstr($thefile, 'http://') && !strstr($thefile, 'https://') && !strstr($thefile, 'ftp://')) {
开发者ID:pankajsinghjarial,项目名称:SYLC,代码行数:31,代码来源:download.php

示例10: readfile

    readfile(GetSystemOption('temp_dir') . $backupname . ".zip ");
    unlink(GetSystemOption('temp_dir') . $backupname . ".zip ");
    exit;
} else {
    # Now we send the output (POSIX)...
    $file = GetSystemOption('temp_dir') . $backupname . ".zip";
    header('Pragma: public');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Cache-Control: private', false);
    header('Content-Description: File Transfer');
    header('Content-Transfer-Encoding: binary');
    header('Content-Type: application/force-download');
    header('Content-Length: ' . filesize($file));
    header('Content-Disposition: attachment; filename=' . $backupname . '.zip');
    readfile_chunked($file);
    unlink(GetSystemOption('temp_dir') . $backupname . ".zip ");
    function readfile_chunked($filename)
    {
        $chunksize = 1 * (1024 * 1024);
        $buffer = '';
        $handle = fopen($filename, 'rb');
        if ($handle === false) {
            return false;
        }
        while (!feof($handle)) {
            $buffer = fread($handle, $chunksize);
            print $buffer;
        }
        return fclose($handle);
    }
开发者ID:shishenkov,项目名称:zpanel,代码行数:31,代码来源:obj_backups.php

示例11: testreadfile_chunked

 public function testreadfile_chunked()
 {
     //execute the method and test if it returns expected values
     $expected = file_get_contents('config.php');
     //retbytes parameter false
     ob_start();
     $actual = readfile_chunked('config.php', false);
     $renderedContent = ob_get_contents();
     ob_end_clean();
     $this->assertTrue($actual);
     $this->assertSame($expected, $renderedContent);
     //retbytes parameter true/default
     ob_start();
     $actual = readfile_chunked('config.php');
     $renderedContent = ob_get_contents();
     ob_end_clean();
     $this->assertEquals($actual, strlen($renderedContent));
     $this->assertSame($expected, $renderedContent);
 }
开发者ID:sacredwebsite,项目名称:SuiteCRM,代码行数:19,代码来源:fileUtilsTest.php

示例12: download

 /**
  * Download a paper
  */
 function download($requiredFile)
 {
     $type = "application/octet-stream";
     $file = $this->filePath($requiredFile->id_phase, $requiredFile->file_code, $requiredFile->file_extension);
     header("Content-disposition: attachment; filename=" . $requiredFile->file_code . $this->id . "." . $requiredFile->file_extension);
     header("Content-Type: application/force-download");
     header("Content-Transfer-Encoding: {$type}\n");
     header("Content-Length: " . filesize($file));
     header("Pragma: no-cache");
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
     header("Expires: 0");
     readfile_chunked($file);
 }
开发者ID:camilorivera,项目名称:INNOVARE,代码行数:16,代码来源:PaperRow.php

示例13: nzshpcrt_download_file

function nzshpcrt_download_file()
{
    global $wpdb, $user_level, $wp_rewrite;
    get_currentuserinfo();
    function readfile_chunked($filename, $retbytes = true)
    {
        $chunksize = 1 * (1024 * 1024);
        // how many bytes per chunk
        $buffer = '';
        $cnt = 0;
        $handle = fopen($filename, 'rb');
        if ($handle === false) {
            return false;
        }
        while (!feof($handle)) {
            $buffer = fread($handle, $chunksize);
            echo $buffer;
            ob_flush();
            flush();
            if ($retbytes) {
                $cnt += strlen($buffer);
            }
        }
        $status = fclose($handle);
        if ($retbytes && $status) {
            return $cnt;
            // return num. bytes delivered like readfile() does.
        }
        return $status;
    }
    if (isset($_GET['downloadid'])) {
        // strip out anything that isnt 'a' to 'z' or '0' to '9'
        //ini_set('max_execution_time',10800);
        $downloadid = preg_replace("/[^a-z0-9]+/i", '', strtolower($_GET['downloadid']));
        $download_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `uniqueid` = '" . $downloadid . "' AND `downloads` > '0' AND `active`='1' LIMIT 1", ARRAY_A);
        if ($download_data == null && is_numeric($downloadid)) {
            $download_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `id` = '" . $downloadid . "' AND `downloads` > '0' AND `active`='1' AND `uniqueid` IS NULL LIMIT 1", ARRAY_A);
        }
        if (get_option('wpsc_ip_lock_downloads') == 1 && $_SERVER['REMOTE_ADDR'] != null) {
            $ip_number = $_SERVER['REMOTE_ADDR'];
            if ($download_data['ip_number'] == '') {
                // if the IP number is not set, set it
                $wpdb->query("UPDATE `" . WPSC_TABLE_DOWNLOAD_STATUS . "` SET `ip_number` = '{$ip_number}' WHERE `id` = '{$download_data['id']}' LIMIT 1");
            } else {
                if ($ip_number != $download_data['ip_number']) {
                    // if the IP number is set but does not match, fail here.
                    // 				return false;
                    exit(WPSC_DOWNLOAD_INVALID);
                }
            }
        }
        //exit("<pre>".print_r($download_data,true)."</pre>");
        if ($download_data != null) {
            if ($download_data['product_id'] > 0) {
                $product_file_id = $wpdb->get_var("SELECT `file` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id`='" . $download_data['product_id'] . "' LIMIT 1");
                $file_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `id`='" . $product_file_id . "' LIMIT 1", ARRAY_A);
            } else {
                $old_file_data = $wpdb->get_row("SELECT `product_id` FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `id`='" . $download_data['fileid'] . "' LIMIT 1", ARRAY_A);
                $product_file_id = $wpdb->get_var("SELECT `file` FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id`='" . $old_file_data['product_id'] . "' LIMIT 1");
                $file_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `id`='" . $product_file_id . "' LIMIT 1", ARRAY_A);
            }
            if ((int) $download_data['downloads'] >= 1) {
                $download_count = (int) $download_data['downloads'] - 1;
            } else {
                $download_count = 0;
            }
            $wpdb->query("UPDATE `" . WPSC_TABLE_DOWNLOAD_STATUS . "` SET `downloads` = '{$download_count}' WHERE `id` = '{$download_data['id']}' LIMIT 1");
            $cart_contents = $wpdb->get_results('SELECT `' . WPSC_TABLE_CART_CONTENTS . '`.*,`' . WPSC_TABLE_PRODUCT_LIST . '`.`file` FROM `' . WPSC_TABLE_CART_CONTENTS . '` LEFT JOIN `' . WPSC_TABLE_PRODUCT_LIST . '` ON `' . WPSC_TABLE_CART_CONTENTS . '`.`prodid`= `' . WPSC_TABLE_PRODUCT_LIST . '`.`id` WHERE `purchaseid` =' . $download_data['purchid'], ARRAY_A);
            $dl = 0;
            foreach ($cart_contents as $cart_content) {
                if ($cart_content['file'] == 1) {
                    $dl++;
                }
            }
            if (count($cart_contents) == $dl) {
                //  	exit('called');
                $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `processed` = '4' WHERE `id` = '" . $download_data['purchid'] . "' LIMIT 1");
            }
            //exit('<pre>'.print_r($cart_contents,true).'</pre>');
            if (is_file(WPSC_FILE_DIR . $file_data['idhash'])) {
                header('Content-Type: ' . $file_data['mimetype']);
                header('Content-Length: ' . filesize(WPSC_FILE_DIR . $file_data['idhash']));
                header('Content-Transfer-Encoding: binary');
                header('Content-Disposition: attachment; filename="' . stripslashes($file_data['filename']) . '"');
                if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] != '') {
                    /*
                    There is a bug in how IE handles downloads from servers using HTTPS, this is part of the fix, you may also need:
                      session_cache_limiter('public');
                      session_cache_expire(30);
                    At the start of your index.php file or before the session is started
                    */
                    header("Pragma: public");
                    header("Expires: 0");
                    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                    header("Cache-Control: public");
                } else {
                    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                }
                $filename = WPSC_FILE_DIR . $file_data['idhash'];
                // destroy the session to allow the file to be downloaded on some buggy browsers and webservers
//.........这里部分代码省略.........
开发者ID:alx,项目名称:SBek-Arak,代码行数:101,代码来源:wp-shopping-cart.old.php

示例14: send_file

/**
 * Send file to download to the user
 * @global stdClass $CFG
 * @global stdClass $COURSE
 * @global stdClass $SESSION
 * @param string $path      The path of the file
 * @param string $filename  The file name
 * @param string $extension The file extension
 */
function send_file($path, $filename, $extension)
{
    global $CFG, $COURSE, $SESSION;
    //print $path . " " . $filename . " " . $extension;exit();
    $filesize = filesize($path);
    //IE compatibiltiy HACK!
    if (ini_get('zlib.output_compression')) {
        ini_set('zlib.output_compression', 'Off');
    }
    //try to disable automatic sid rewrite in cookieless mode
    @ini_set("session.use_trans_sid", "false");
    @header('Content-Disposition: inline; filename="' . $filename . '"');
    $lifetime = $lifetime = 86400;
    @header('Cache-Control: max-age=' . $lifetime);
    @header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $lifetime) . ' GMT');
    @header('Pragma: ');
    // Just send it out raw
    @header('Content-Length: ' . $filesize);
    @header('Content-Type: ' . $mimetype);
    while (@ob_end_flush()) {
    }
    //flush the buffers - save memory and disable sid rewrite
    readfile_chunked($path);
    die;
    //no more chars to output!!!
}
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:35,代码来源:file.php

示例15: viewAsImage

 public function viewAsImage($max_size = 0)
 {
     $max_size = intval($max_size);
     if (!($dimensions = $this->getImageDimensions($max_size))) {
         log_message("file::viewAsImage({$this->id}) can not find file1 '{$filepath}'", LOG_MESSAGE_MISSING_FILES);
         return;
     }
     $filepath = $dimensions['filepath'];
     $new_width = $dimensions['new_width'];
     $new_height = $dimensions['new_height'];
     $width = $dimensions['width'];
     $height = $dimensions['height'];
     $filesize = filesize($filepath);
     /**
      * just provide the original file
      */
     if (!$dimensions['downscale']) {
         header('Content-Length: ' . $filesize);
         header('Content-Type: ' . $this->mimetype);
         header("Content-Disposition: inline; filename={$this->org_filename}");
         header("Cache-Control: public");
         header('Last-Modified: ' . gmdate("D, j M Y G:i:s T", strToClientTime($this->modified)));
         if ($filesize > 1000000) {
             readfile_chunked($filepath);
         } else {
             readfile($filepath);
         }
         return;
     }
     /**
      * rescale with gd
      */
     if (!function_exists('imagecreatetruecolor')) {
         log_message("file::viewAsImage({$this->id}) gd not installed", LOG_MESSAGE_MISSING_FILES);
         return;
     }
     ### check if cached file exists
     $md5 = md5(http_build_query(array('filepath' => $filepath, 'new_width' => $new_width, 'new_height' => $new_height)));
     $cached_filepath = confGet('DIR_IMAGE_CACHE') . "/" . $md5 . ".jpg";
     if (file_exists($cached_filepath)) {
         header('Content-Length: ' . filesize($cached_filepath));
         header('Content-Type: ' . $this->mimetype);
         header("Content-Disposition: inline; filename= {$this->org_filename}");
         header("Cache-Control: public");
         header('Last-Modified: ' . gmdate("D, j M Y G:i:s T", strToClientTime($this->modified)));
         header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60 * 60 * 24 * 365) . " GMT");
         readfile($cached_filepath);
         return;
     }
     $image_new = NULL;
     ### downscale
     if ($this->mimetype == 'image/jpeg' || $this->mimetype == 'image/jpg' || $this->mimetype == 'image/pjpeg') {
         $image = imagecreatefromjpeg($filepath);
     } else {
         if ($this->mimetype == 'image/png' || $this->mimetype == 'image/x-png') {
             $image = imagecreatefrompng($filepath);
         } else {
             if ($this->mimetype == 'image/gif') {
                 $image = imagecreatefromgif($filepath);
             } else {
                 return NULL;
             }
         }
     }
     ### Downscale image and stream content
     header('Content-Type: ' . 'image/jpeg');
     header("Cache-Control: public");
     ### Tell browser to cache forever, because the file will never change
     header("Last-Modified: " . gmdate('r', strToClientTime($this->modified)));
     header("Expires: " . gmdate("D, d M Y H:i:s", time() + 60 * 60 * 24 * 365) . " GMT");
     $image_new = imagecreatetruecolor($new_width, $new_height) or die("Cannot Initialize new GD image stream");
     if (imagecopyresampled($image_new, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height)) {
         imagejpeg($image_new);
     } else {
         imagejpeg($image);
     }
     ### write cached file
     if ($image_new) {
         imagejpeg($image_new, $cached_filepath);
         imagedestroy($image_new);
     }
 }
开发者ID:Bremaweb,项目名称:streber-1,代码行数:82,代码来源:class_file.inc.php


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