简体   繁体   English

PHP如何在上传过程中获取tmp文件大小

[英]PHP How to get tmp file size during Upload

I want to implement PHP uploading Progress Bar and My idea is to get the size of $_FILES['file']['tmp'] after each second. 我想实现PHP上传进度条,我的想法是每秒钟获取$ _FILES ['file'] ['tmp']的大小。
But what is problem here, when a file is uploading there exist no file in temp directory set in php.ini but file successfully uploaded and when i try to get size of $_FILES['file']['tmp'] it show error warning. 但是这里的问题是,当文件上传时,在php.ini中设置的临时目录中没有文件,但是文件成功上传,并且当我尝试获取$ _FILES ['file'] ['tmp']的大小时,它显示错误警告。

<br />
<b>Warning</b>:  filesize() [<a href='function.filesize'>function.filesize</a>]: stat failed for D:\Program Files\webserver\temp\phpDD05.tmp in <b>D:\Program Files\webserver\www\test\upload\uploading.php</b> on line <b>5</b><br />

which mean i think file not exist. 这意味着我认为文件不存在。 How we can converge this idea to success for uploading with progress bar 如何使用进度条将这个想法融合为成功,以便成功上传

You can try something like this to see if there's an error, then grab the file size if there are no errors. 您可以尝试执行类似的操作以查看是否有错误,然后在没有错误的情况下获取文件大小。

<?php
if ($_FILES["file"]["error"] > 0)
{
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
}
?>

What does that do for you? 这对您有什么作用?

File is incapsulated in the POST request, so you need something outside your form that uploads the file and something that monitors periodically the file. 文件已封装在POST请求中,因此您需要在表单外部上传文件的文件以及需要定期监视文件的文件。 I suggest some already made solutions like ajax upload progress bar or similar 我建议一些已经提出的解决方案,例如ajax上传进度栏或类似的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM