You are here: Re: [PHP] getting file size before upload « PHP « IT news, forums, messages
Re: [PHP] getting file size before upload

Posted by Matthew Weier O'Phinney on 07/19/05 23:00

* "Jay Blanchard" <jay.blanchard@niicommunications.com>:
> [snip]
> I know it is a often asked question, but after googling for about
> 2hours and trying out some wired examples I am still not any closer to
> a solution. So I was hoping to find expert advice here.
>
> I want to save the user the hastle of uploading a 2MB file and waiting
> for a long time for an error message that the file is to big.
>
> Is there any usefull workaround in warning the user that he is about
> to upload a 2MB file and only smaller files are supported? I tried
> around with megaupload:
> http://sourceforge.net/projects/megaupload
> to get a progress bar and to get the file size prior to upload, but
> that somehow does not work the way I want it to.
>
> Is there an easier solution without perl,just with PHP or/and JS?
> [/snip]
>
> http://www.php.net/stat

The OP wants a solution that is client-side -- stat() would be
server-side.

And, to answer the OP's question, no, there is not a reliable way to do
this. You can provide some hints via the HTML form -- set hidden keys
for MAX_UPLOAD_SIZE, for instance -- but many browsers ignore these.

My understanding is that it's possible to use javascript in some cases
to determine the file size on the upload element's population, but that
is going to be unreliable as well, due to differences in client OS and
browser javascript implementations.

The easiest "solution" is to simply provide some warning text indicating
that the file size should not exceed a certain threshold -- and give
back a nice, big error message when it does so they know why the upload
failed.

--
Matthew Weier O'Phinney
Zend Certified Engineer
http://weierophinney.net/matthew/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация