user656521
user656521

Reputation:

How to calculate the size of a file?

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 ??

Upvotes: 1

Views: 805

Answers (3)

Gumbo
Gumbo

Reputation: 655239

You can use $_FILES['userfile']['size'] where userfile is the name of your file input field.

Upvotes: 2

ngduc
ngduc

Reputation: 1413

What you need is this:

http://php.net/manual/en/function.filesize.php

Upvotes: 9

codaddict
codaddict

Reputation: 455020

Have you tried filesize function ?

Upvotes: 4

Related Questions