/    Sign up×
Community /Pin to ProfileBookmark

checking upload size before upload takes place

Hi,

I have a slight issue at the moment as by when I am uploading a file larger than the php.ini allows I am not getting to the point of passing back an error of file to big.

How can I get it to check the file size at the first point of upload? ie. at the same point it realising it is past the php.ini upload size?

I have messed around with $_server[‘content_length’] but that too only appear to work once the file is uploaded.

Thanks
k0r54

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJan 22.2010 — Only by using flash or a java applet. PHP should be giving you errors if the file is too big though:

http://uk.php.net/manual/en/features.file-upload.errors.php
Copy linkTweet thisAlerts:
@SrWebDeveloperJan 22.2010 — I found a cool Ajax/PHP/Javascript method that generates an incremental copy of the file in the PHP upload temp path while the upload process is waiting for the end. This means the moment the upload starts you can query all kinds of information from that copied file including its filesize, filename, etc. You can modify the code to compare the file size with an imposed limit.

There are limitations - the author discusses them on the web site, so don't address them to me.

I downloaded it and tried it - it actually works! The author is Italian so you'll see that in the "Upload" button next to the browse button, and it outputs basic file info via print_r() for the demo.

No solution is perfect, this is just an alternative to the excellent (and much more common) advice given earlier.

-jim
×

Success!

Help @k0r54 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...