Current location: Hot Scripts Forums » Programming Languages » PHP » Check uploaded files size


Check uploaded files size

Reply
  #1 (permalink)  
Old 09-27-06, 01:25 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Check uploaded files size

I have a PHP script to upload files.
Each uploaded file name, size and type are stored in mysql table. I have a table called files_temp (temporary table for uploaded files).

The mySQL table:

Code:
id    name               size       type
1     File.exe          79360     application/x-sdlc
2     File2.exe        12323     application/x-sdlc
I don't store the files as BLOB, i store only the details in mySQL table. I have a separate directory on Web server to store each uploaded file.
I want to check the total size for each uploaded file. PHP need to tell the web browser, hey your files are bigger than 10MB.

Code:
79360 +
12323
-------
91683
I know exist a way to do this using SUM in mySQL but I don't know what I need to do to get the last files uploaded from user.
mysql_insert_id not return more than last row. If more files uploaded more rows created.

Exist a way to check the files size after upload? I don't want to do this only with mySQL, I wait any idea or better suggestions.

Thanks!
Reply With Quote
  #2 (permalink)  
Old 09-27-06, 02:36 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Hm, do you want to check the size when uploading? If so, you don't need MySQL. You can simply do.
PHP Code:



if ($_FILES['file']['size'] > 10485760)
{
    echo 
'hey your files are bigger than 10MB.';
    exit();
}
else
{
   
// Insert into database

Reply With Quote
  #3 (permalink)  
Old 09-27-06, 03:17 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks nico_swd !

Which formula help me to calculate the allowed size?
For example I want 1MB not 10MB.
Reply With Quote
  #4 (permalink)  
Old 09-27-06, 03:20 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Reply With Quote
  #5 (permalink)  
Old 09-27-06, 03:24 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
cool, thanks
Reply With Quote
  #6 (permalink)  
Old 09-27-06, 01:52 PM
Marcelino Marcelino is offline
Newbie Coder
 
Join Date: Sep 2006
Location: Cluj-Napoca, Romania
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
I don't know how, but I would recommend you to make this kind of script in Java. In this way you could avoid uploading large file to your server before making any validating step.

Last edited by Marcelino; 09-27-06 at 02:09 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to differenciate Newly created files from old files in a directory itssami PHP 1 08-14-06 09:41 AM
Showing Uploaded Files, Help! Should be fairly easy for you! Scientist Script Requests 3 02-04-06 02:17 PM
Upload Script Problem!!! seanknighton Perl 0 03-21-04 09:54 PM
need help with viewing uploaded image on webpage? mikewooten PHP 0 03-16-04 07:39 PM
netadmin project - delete files georgeminton Visual Basic 0 03-03-04 04:03 PM


All times are GMT -5. The time now is 05:40 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.