PHP断点续传-HTTP
/**
* PHP-HTTP断点续传实现
* @param string $path: 文件所在路径
* @param string $file: 文件名
* @return void
*/
function download($path,$file) {
$real = $path.'/'.$file;
if(!file_exists($real)) {
return false;
}
$size = filesize($real);
$size2 = $size-1;
$range = 0;
if(isset($_SERVER['HTTP_RANGE'])) {
header('HTTP /1.1 206 Partial Content');
$range = str_replace('=','-',$_SERVER['HTTP_RANGE']);
$range = explode('-',$range);
$range = trim($range[1]);
header('Content-Length:'.$size);
header('Content-Range: bytes '.$range.'-'.$size2.'/'.$size);
} else {
header('Content-Length:'.$size);
header('Content-Range: bytes 0-'.$size2.'/'.$size);
}
header('Accenpt-Ranges: bytes');
header('application/octet-stream');
header("Cache-control: public");
header("Pragma: public");
//解决在IE中下载时中文乱码问题
$ua = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/MSIE/',$ua)) {
$ie_filename = str_replace('+','%20',urlencode($file));
header('Content-Dispositon:attachment; filename='.$ie_filename);
} else {
header('Content-Dispositon:attachment; filename='.$file);
}
$fp = fopen($real,'rb+');
fseek($fp,$range);
while(!feof($fp)) {
set_time_limit(0);
print(fread($fp,1024));
flush();
ob_flush();
}
fclose($fp);
}
/*End of PHP*/

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Use Java's File.length() function to get the size of a file. File size is a very common requirement when dealing with file operations. Java provides a very convenient way to get the size of a file, that is, using the length() method of the File class. . This article will introduce how to use this method to get the size of a file and give corresponding code examples. First, we need to create a File object to represent the file we want to get the size of. Here is how to create a File object: Filef

[SpringBoot] Passing parameters in the Header through Feign calls How to pass Header parameters through Feign Problem description When we use Feign to request the Api interface of another service in Spring Cloud, there is a need to pass the parameters in the Header. If no special processing is done, it will The parameters in the Header will be lost. Solution 1: Pass it through @RequestHeader(name="headerName"). For example: Feign is defined as follows @FeignClient(name="service-name")pub

The Linux header refers to the beginning of a file or data stream, which is used to contain metadata about the content. By correctly writing and using Header files, developers can better utilize system resources and improve code readability and Maintainability.

PHP is a powerful programming language that can be used to create dynamic websites and web applications. One of the most powerful features is PHP’s header() method. In this article, we will explore how to use PHP’s header() method to adjust web pages.

How to implement jump in php header: 1. Use "Header("Location:$url");" syntax to implement jump; 2. Use if judgment to implement jump, with jump statements such as "if($_COOKIE[" u_type"]){ header('location:register.php'); } else{ setcookie('u_type','1','86400*360');".

Differences: 1. The head tag is used to define the head of the document, which is a container for all head elements, and the header tag is used to define the header (introduction information) of the document; 2. All browsers support the head tag, and older versions of browsers None of the browsers support the header tag, and browsers such as IE9+ and above are required to support the header tag.

This article will explain in detail how PHP returns all the values of an array to form an array. The editor thinks it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. Using the array_values() function The array_values() function returns an array of all the values in an array. It does not preserve the keys of the original array. $array=["foo"=>"bar","baz"=>"qux"];$values=array_values($array);//$values will be ["bar","qux"]Using a loop can Use a loop to manually get all the values of the array and add them to a new

Nginx can distribute requests to different servers based on custom identifiers in the request headers. Specifically, you can use the map directive to map the custom identifier in the request header to a different backend server address, and then use the proxy_pass directive to forward the request to the corresponding backend server. The following is an example configuration file: http{map$http_my_header$backend{defaultbackend1.example.com;value1backend2.example.com;value2backend3.example.com;}upstreambackend1{serv
