如何判断一个文件被客户端成功下载
rt,如何能够确认文件被客户端成功下载?
------解决方案--------------------
一般情况下当输出完头以后就直接将整个文件输出出去
通常用的是 ceho、print 有的干脆用 readfile
这样 php 就没有机会去判断用户是否终止了下载
你需要在循环中用较小的块,通过 sprintf 输出文件内容
springf 函数会返回一个表示输出了多少字符的数。你可以累计这个数,并与文件长度进行比较
从而判断下载是否完成
------解决方案--------------------
基本上是没法判断的。。。
------解决方案--------------------
基于http是没办法做到的。比如服务器返回了2000个字节让你下载保存,这时候你在你在浏览器点了取消按钮,或者下载到一半取消,再或者下载完成,这些个动作只在客户端浏览器执行,并不会将状态通知服务器。
------解决方案--------------------
说的不对,应该说基于浏览器的客户端无法做到,下载保存那些动作是浏览器帮你处理的。
如果说你自己写个客户端,很容易可以判断,计算返回字节数,统计保存成文件的字节数两个一比较就行。
------解决方案--------------------
IE下可使用ActiveX,FireFox下可以使用NPAPI
------解决方案--------------------
一般来讲,要判断文件下载完毕的话需要通过控件来实现。普通的JS是没法判断的。
------解决方案--------------------
强,这个不错。最近我们公司也在做一个OA项目,也要判断文件下载完成的事件,正需要一个这样的HTTP文件下载控件,能否把地址发一下。谢谢。
------解决方案--------------------
这个好像是Xproer.HttpDownloader。可以在网上直接搜到。
------解决方案--------------------
如果是通过PHP页面下载的话可以在PHP页面中直接判断。如果想在客户端判断的话,需要借助于插件来实现。
------解决方案--------------------
我们之前给政府做的一个文档管理类的项目也是用的这个控件。感觉不错。整合也简单。
------解决方案--------------------
是吗?是否要给你段代码看看才相信?
------解决方案--------------------
send_file 函数是在网上找的,写的并不好,但他确能保证数据不丢失
在此基础上做了些改动,代码中有注释
send_file('03.bmp',1);//为了测试方便我取了较小的块尺寸<br> <br> function send_file($file, $speed = 100) { <br> <br> //First, see if the file exists <br> if (!is_file($file)) { <br> die("<b>404 File not found!</b>"); <br> } <br> //Gather relevent info about file <br> $filename = basename($file); <br> $file_extension = strtolower(substr(strrchr($filename,"."),1)); <br> // This will set the Content-Type to the appropriate setting for the file <div class="clear"> </div>

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


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

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version
Useful JavaScript development tools