Dynadot

PHP file upload, check file size before upload

Spaceship Spaceship
Watch
Impact
12
Hi,

I am building a imagehost application in PHP and was trying to figure out how I could check the file size before the file is uploaded to save me precious bandwith.

Since PHP is server side I doubt there is any solution in PHP, but could it be solved in another way?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Well if you wanted to set a limit

Code:
<input name="MAX_FILE_SIZE" value="xxxxxx" type="hidden" />

Put than in your form

Or you could use http://www.pixeline.be/experiments/jqUploader/ to turn your html form into a flash one.
 
0
•••
bomb said:
Well if you wanted to set a limit

Code:
<input name="MAX_FILE_SIZE" value="xxxxxx" type="hidden" />

Put than in your form

Or you could use http://www.pixeline.be/experiments/jqUploader/ to turn your html form into a flash one.

The limit is already set, that's not what I want to do. I want the application to check if the limit is exceeded BEFORE the file has actually been uploaded to the server. I will se what jqUploader does..
 
0
•••
This?

if(($_FILES["uploaded_file"]["size"] < 3000000)){
upload
}else{
do not upload
}


for less than 3mb.. alter as u need


I have a nice uploading script if you want me to send you the php file over so you can pick at it?
 
Last edited:
0
•••
NVD said:
($_FILES["uploaded_file"]["size"] < 3000000)

Do this actually measure the size of the file before it is uploaded? What I've read it seems this doesn't do it, because it measures the size of the file after it has been uploaded to the server, where it stores it in a tmp_folder, and wheater or not its the allowed size, it will be moved to another folder or removed from the server.

Yeah, you could definately send me the PHP-file if you'd like, maybe I can find some useful tips and tricks how to do things. I've never worked with files and PHP before. I'll throw a PM your way ;)
 
0
•••
Yes, it will temporarily upload it, but if the file is not over the limit you set in maxfilesize, then does that really matter? if it is going to be uploaded anyway...

I dont think you can check the exact file size of a file before it is on the server, that would require the php to access your pc somehow and find it out.. So i dont think its possible in php. Its a temp folder or nothing :p
 
0
•••
You can't check the file size before it is uploaded using PHP. You would need to use javascript however that is easy circumvented.
 
0
•••
0
•••
To expand on what Peter said, PHP is a server-side language and can't access the user's file system. Therefore PHP can't check the file size until the file is actually uploaded to the server. You have to use a client-side language like Javascript, but it is easy to disable.
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back