创建自定义上传进度条

2023-12-01php开发问题
1

本文介绍了创建自定义上传进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我见过所有的上传进度条插件、小部件等——它们都很糟糕.它们要么太笨重,包含太多无用的代码,要么无法正常工作.

I have seen all the upload progress bar plugins, widgets, etc. – they all suck. They're either too bulky with too much useless code or they don't work.

我想知道在哪里可以阅读有关如何显示简单上传进度指示器的信息.大多数浏览器在下方都有一个状态进度条,但在与客户打交道时仅使用它不是很专业.

What I want to know is where I can read up on how to display an easy upload progress indicator. Most browsers have a status progress bar on them below, but it isn't very professional to use just that when dealing with clients.

浏览器是如何做到的?我想知道浏览器如何工作以指示上传状态的内部结构,以便我可以使用 PHP &jQuery.

How does the browser do it? I want to know the internals of how the browser works with for indicating the status of something uploading so that maybe I can make something using PHP & jquery.

谢谢.

推荐答案

既然要使用 PHP,那我先从 uploadprogress 扩展(默认情况下,在上传完成之前,PHP 不会为您提供任何数据;此扩展提供此类服务器端功能).请注意,它需要 PHP 5.2+,并且可能对配置选项很挑剔.另请参阅其 评论和演示和故障排除提示).PHP 文档评论中提供了一个简短的概述.

Since you want to use PHP, I'd start with the uploadprogress extension (PHP doesn't, by default, give you any data about until the upload is completed; this extension provides such server-side functionality). Note that it requires PHP 5.2+ and can be picky about configuration options. Also see its commentary and demo and troubleshooting hints). A short overview available in PHP documentation comments.

使用扩展程序,您可以获得一些上传统计信息;然后您可以通过 AJAX 轮询服务器并更新某种进度条.

Using the extension, you can get some stats on the upload; then you can poll the server through AJAX and update some sort of progress bar.

更具体一点:

  • 获取表单的唯一标识符,并将其包含在隐藏字段中
  • 上传应该在 IFRAME 中运行 - 某些浏览器不允许 DOM 更新到运行上传的同一页面
  • 通过 AJAX 轮询服务器(使用标识符指定您感兴趣的上传内容)并解析结果(IIRC,您会得到类似bytes_uploaded => 123, content-length=> 1000")
  • 更新您的进度条(显示方式由您决定,我使用x% done"加上图形条)
  • 表单上传成功后重定向整个页面

(哦,顺便说一句,检查 PHP 的 upload_max_filesize 和 post_max_size 设置,因为它们都限制了最大上传大小)

(Oh, and btw, check PHP's upload_max_filesize and post_max_size settings, as both limit the maximum upload size)

这篇关于创建自定义上传进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17