CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 getfilesize question

Print topic Send  topic

Author Message
kirchaj

Posts: 215
Posted: 06/15/2007, 7:38 AM

I am trying to display the file size of an uploaded file using the following code

$stufilesize = $student_upload->Hidden_stu_upld_filename->GetFileSize();

and I keep getting the following error on that line. Any ideas what I am doing wrong or how I should be doing this? Thanks.



Fatal error: Call to undefined function: getfilesize() in /var/www/html/porttest/student/student_uploads_events.php on line 44


kirchaj
View profile  Send private message
mamboBROWN


Posts: 1713
Posted: 06/15/2007, 3:55 PM

kirchaj,
I think that you are using the function in the wrong way. Checkout this link: http://docs.codecharge.com/studio31/html/Components/RTP...eSizeLimit.html
View profile  Send private message
kirchaj

Posts: 215
Posted: 06/18/2007, 6:09 AM

Thanks Mambobrown.

Maybe I need to ask the question in another way.

I have a grid that shows files that students have uploaded previously. I would like to have a column that shows the file size of the file that was uploaded.

Any ideas on how to do this?

TK
View profile  Send private message
mamboBROWN


Posts: 1713
Posted: 06/18/2007, 5:22 PM

kirchaj
The actual PHP function that you are looking for is filesize(). Here is a link to the function discription: http://us.php.net/manual/en/function.filesize.php
View profile  Send private message
2467

Posts: 47
Posted: 08/18/2007, 5:44 AM

Anybody know how to get file size in a grid beside the files link ?


Thanks in advance
View profile  Send private message
wkempees
Posted: 08/19/2007, 4:36 AM

MamboBrown answered that question.
At grid time you knwo the full filepath+name.
using the PhP filesize() function feeding it the full filepath+name should
result in the filesize.

I however go about this another way.
At upload all file details are available (that in fact is where kindrans
function is)
I let the user upload the file storing not only path and filename but also
size and type.
That way in a grid I can present whatever I like, and at download I know
what will be downloaded
and more important by it's type I can dynalically change the MIME type.

There are always more ways to skin a cat.
Walter

"2467" <2467@forum.codecharge> schreef in bericht
news:546c6e9af82692@news.codecharge.com...
> Anybody know how to get file size in a grid beside the files link ?
>
>
> Thanks in advance
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

dirksamson

Posts: 32
Posted: 08/20/2007, 1:32 AM

... and when you have "found" the filesize don't forget the icing on the cake:

function file_size($size)
// function to convert to Mb, Kb and bytes
{
$megabyte = 1024 * 1024;
if ($size > $megabyte)
// literal.float
{
$re_sized = sprintf("%01.2f", $size / $megabyte)." Mb";
}
elseif ($size > 1024) {
$re_sized = sprintf("%01.2f", $size / 1024)." Kb";
}
else {
$re_sized = $size." byte(s)";
}
return $re_sized;
}
_________________
Dirk
View profile  Send private message
2467

Posts: 47
Posted: 08/20/2007, 1:38 AM

Quote :
wkempees

I let the user upload the file storing not only path and filename but also size and type.

Walter do you make this in automatic way or let the user manually fill into type field and size field ?

I'm interested something automatically.
View profile  Send private message
wkempees
Posted: 08/20/2007, 3:46 AM

Will try and post an example.
In the PhP Upload component description (docs/help) the GetFileSize
method is available for the afterupload event.

Walter

"2467" <2467@forum.codecharge> schreef in bericht
news:546c9531335c34@news.codecharge.com...
>
Quote :
> wkempees
>
> I let the user upload the file storing not only path and filename but also
> size
> and type.
>
> Walter do you make this in automatic way or let the user manually fill
> into
> type field and size field ?
>
> I'm interested something automatically.
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

2467

Posts: 47
Posted: 08/23/2007, 10:05 AM

Hi all.

This is how can you solve the file size problem if sometimes you need it.

In record form I did like this:

1. Added a hidden field named " UploadFileSize "
2. In "before insert event" and "before update event" I've added :

// -------------------------

$fsize = $Component->{FileUpload1}->GetFileSize();
$Component->{UploadFileSize}->SetValue(($fsize / 1024) / 1024);

// -------------------------

Now I have into database the size of the uploaded file in MB (megabytes).

3. Into the grid I have one label named "LabelUploadFileSize" that for source have "UploadFileSize" field and Data Type set to float with format 0.000 because of converting from bytes to mega bytes.


That is my solution in the end and thanks for your valuable help.

View profile  Send private message
Wkempees
Posted: 08/24/2007, 2:20 AM

Well done.
Saves me creating example.
You are saving the actual numeric size.
You could apply the (dirksamson) file_size function (we do ours too)
and save the result to a (varchar) text field in the database.
Only if you do not need to use filesize in calculations though.

Walter
Wkempees
Posted: 08/24/2007, 2:23 AM

just one more thing:
You do BeforeInsert (right) and BeforeUpdate.
The Before Update IMHO will never be used as file component always does
Insert, Delete/Insert and not update.
Am I right?

Walter
rv1234

Posts: 1
Posted: 08/25/2007, 2:21 AM

Quote dirksamson:
... and when you have "found" the filesize don't forget the icing on the cake:

function file_size($size)
// function to convert to Mb, Kb and bytes
{
$megabyte = 1024 * 1024;
if ($size > $megabyte)
// literal.float
{
$re_sized = sprintf("%01.2f", $size / $megabyte)." Mb";
}
elseif ($size > 1024) {
$re_sized = sprintf("%01.2f", $size / 1024)." Kb";
}
else {
$re_sized = $size." byte(s)";
}
return $re_sized;
}
View profile  Send private message
2467

Posts: 47
Posted: 08/26/2007, 4:17 AM

Quote Wkempees:
just one more thing:
You do BeforeInsert (right) and BeforeUpdate.
The Before Update IMHO will never be used as file component always does
Insert, Delete/Insert and not update.
Am I right?

Walter

- Yes, Walter you are right, but my case was different because I had already uploaded files and I have data into the database, so I use update button to update filesize field ;)

- Other solution to convert to MB, KB ... using function provided looks good but I didn't know how to implement it, and didn't have to much time to experiment.

Any feedback how to us that combined with my solution is welcome.

Greetings to all
View profile  Send private message
wkempees
Posted: 08/26/2007, 5:55 AM

Your solution

Quote :
1. Added a hidden field named " UploadFileSize "
2. In "before insert event" and "before update event" I've added :

// -------------------------

$fsize = $Component->{FileUpload1}->GetFileSize();
$Component->{UploadFileSize}->SetValue(($fsize / 1024) / 1024);

// -------------------------


My fsize() function

  
function fsize($size) {  
$a = array("b", "Kb", "Mb", "Gb", "Tb", "Pb");  
while ($size >= 1024) {  
$size /= 1024;  
$pos++;  
}  
return round($size,2)." ".$a[$pos];  
}  

Put the above code somewhere in the white area of your _event.php file for
instance at the bottom, or include it in common.php or in a general included
functions.php file.
Your code would evolve into:

  
  
$fsize = fsize( $Component->{FileUpload1}->GetFileSize() );  
$Component->{UploadFileSize}->SetValue($fsize);  

or even:

  
  
$Component->{UploadFileSize}->SetValue( fsize(   
$Component->{FileUpload1}->GetFileSize() ) );  

Walter









"2467" <2467@forum.codecharge> schreef in bericht
news:546d1616378817@news.codecharge.com...
>
Quote Wkempees:
> just one more thing:
> You do BeforeInsert (right) and BeforeUpdate.
> The Before Update IMHO will never be used as file component always does
> Insert, Delete/Insert and not update.
> Am I right?
>
> Walter
>
>
> - Yes, Walter you are right, but my case was different because I had
> already
> uploaded files and I have data into the database, so I use update button
> to
> update filesize field ;)
>
> - Other solution to convert to MB, KB ... using function provided looks
> good
> but I didn't know how to implement it, and didn't have to much time to
> experiment.
>
> Any feedback how to us that combined with my solution is welcome.
>
> Greetings to all
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

2467

Posts: 47
Posted: 08/28/2007, 6:00 AM

Thank you Walter too much.

Working perfect

Best regards
View profile  Send private message
wkempees
Posted: 08/28/2007, 7:26 AM

;-)

Walter


Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.