如何计算文件的大小?
我已使用网络脚本将文件上传到我的网络服务器。那么如果我需要获取它的大小,如何通过 php 获取它?
<?php
session_start();
define('incall', true);
include("connection.php");
if(!@include_once('config.php'))
{
header('HTTP/1.0 404 Not Found');
exit;
}
$to=$_POST['to'];
$message = str_replace('{link}', $download_path.$_POST['filename'].'.mp3', $email_body);
echo $fname." size";
die;
$fname=$download_path.$_POST['filename'].'.mp3';
$headers = "From: ".$_POST['from'];
$subject=$_POST['subject'];
$date=date("Y/m/d");
$time=date('h:i:s A');
$size=filesize('$fname');
$username=$_SESSION['username'];
if(mail($to, $subject, $message, $headers))
{
$query=mysql_query("INSERT INTO sent values('$username', '$to','$date', '$time', '.mp3', '$size' )");
header("location:mailsent.php?");
}
else
exit('Error! VoiceMail not be send.');
?>
我在电子邮件中收到下载链接。但 $fname 仍然不存在。我想知道为什么?
I have uploaded a file to my web server using a web script. So If I need to get the size of that, how can I get it through the php ?
<?php
session_start();
define('incall', true);
include("connection.php");
if(!@include_once('config.php'))
{
header('HTTP/1.0 404 Not Found');
exit;
}
$to=$_POST['to'];
$message = str_replace('{link}', $download_path.$_POST['filename'].'.mp3', $email_body);
echo $fname." size";
die;
$fname=$download_path.$_POST['filename'].'.mp3';
$headers = "From: ".$_POST['from'];
$subject=$_POST['subject'];
$date=date("Y/m/d");
$time=date('h:i:s A');
$size=filesize('$fname');
$username=$_SESSION['username'];
if(mail($to, $subject, $message, $headers))
{
$query=mysql_query("INSERT INTO sent values('$username', '$to','$date', '$time', '.mp3', '$size' )");
header("location:mailsent.php?");
}
else
exit('Error! VoiceMail not be send.');
?>
I'm getting the download link in the email. But still the $fname is not existing. I wonder why ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你需要的是这样的:
http://php.net/manual/en/function.filesize .php
What you need is this:
http://php.net/manual/en/function.filesize.php
您是否尝试过 filesize 函数?
Have you tried filesize function ?
您可以使用
$_FILES['userfile']['size']
其中 userfile 是您的 file 输入字段的名称。You can use
$_FILES['userfile']['size']
where userfile is the name of your file input field.