Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
SIze of files in b,kb and mb
Old 01-05-2010, 05:58 AM SIze of files in b,kb and mb
Average Talker

Posts: 28
Name: Dario
Trades: 0
this is part of my script for uploading
How to show size in kb, mb and bytes - I want to show size of uploaded file in all 3 sizes?


PHP Code:
<?php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path"files/temp/".$HTTP_POST_FILES['ufile']['name'];
if(
$ufile !=none)
{
if(
copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{

echo 
"Successful<BR/><BR/>";

//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "<strong>File Name: </strong>".$HTTP_POST_FILES['ufile']['name']."<BR/><BR/>";
echo 
"<strong>File Size: </strong><br>".$HTTP_POST_FILES['ufile']['size']." bytes<BR/><BR/>";


echo 
"<strong>File Type: </strong>".$HTTP_POST_FILES['ufile']['type']."<BR/><BR/>";

}
else
{
echo 
"Error";
}
}

?>
Dario is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-05-2010, 07:34 AM Re: SIze of files in b,kb and mb
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
bytes/1024 == kilobytes.

kilobytes/1024 == Megabytes.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-05-2010, 09:03 AM Re: SIze of files in b,kb and mb
Average Talker

Posts: 28
Name: Dario
Trades: 0
i know that, but how to include that in script?
Dario is offline
Reply With Quote
View Public Profile
 
Old 01-05-2010, 09:05 AM Re: SIze of files in b,kb and mb
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
PHP Code:
echo($HTTP_POST_FILES['ufile']['size']/1024) . 'Kb' 
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-05-2010, 09:46 AM Re: SIze of files in b,kb and mb
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Here is a handy function I found and is useful. The bytes is passed by reference, but I don't think it's really necessary.

PHP Code:
  function byte_convert(&$bytes)
  {
    
$b = (int)$bytes;
    
$s = array('B''kB''MB''GB''TB');
    if (
$b 0)
    {
      return 
'0 ' $s[0];
    }
    
    
$con 1024;
    
$e = (int)log($b$con);
    
    return 
number_format(round($b pow($con$e), 2), 2'.' ,',') . ' ' $s[$e];
  } 
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 01-05-2010, 01:36 PM Re: SIze of files in b,kb and mb
Average Talker

Posts: 28
Name: Dario
Trades: 0
Quote:
Originally Posted by chrishirst View Post
PHP Code:
echo($HTTP_POST_FILES['ufile']['size']/1024) . 'Kb' 
thanks how to "round" that?
Dario is offline
Reply With Quote
View Public Profile
 
Old 01-05-2010, 01:44 PM Re: SIze of files in b,kb and mb
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://uk.php.net/round
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to SIze of files in b,kb and mb
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24372 seconds with 12 queries