473,805 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checking File Size Before Upload

Hi all,

I am not a developer, but I work with several and am posting this for
them. We are trying to determine whether it is possible to check the
size of a file before a user uploads it.

Everything I've read suggests that this is impossible (or at least very
difficult) in PHP, and this makes sense for a server-side language.
What gives me pause, however, is the fact that when a user tries to
upload a file larger than the max file size we allow, an error appears
in our error log immediately -- yet the upload continues.

So somehow PHP must be recognizing that the file is too big well before
it's been uploaded. The question is how -- and how do we make the leap
from that recognition to an immediate halt of the upload?

Aug 22 '06
19 9277
Andy Hassall wrote:
Ah! Interesting - thanks.

So PHP could - in theory - send the response back as a 417 and populate
$_FILES with a suitable error.
In theory. I have never seen IE sending an expect 100-continue header.
Maybe Firefox does. I doubt it though. In a way it is a limitation of
the specs, as I don't need a pragmatic way by which this feature could
be implemented. Since existing servers do not send the 100 Continue
message, the browser has to rely on some kind of a timeout. That would,
of course, slow things down significantly. What is needed is a header
for server to communicate to the client that it's capable of emitting a
100-continue. Then again, come to think of it, the whole thing is
really useless, since there's no information in the request headers
that tells you the file size or other criteria by which you might
reject the request body.

It's easier to handle this on the client side. The input=file element
should expose the size of the file selected. An element for uploading
multiple files would be nice too. That and a onSubmitProgres s event for
monitoring the upload progress... The lack of innovation really sucks.

Aug 23 '06 #11
"Schraalhan s Keukenmeester" <fi************ ********@xsfour all.ennelpíse v
diskusním príspevku news:44******** **************@ news.xs4all.nl. ..
Luke - ea********@gmai l.com wrote:
I believe some choose a javascript solution to have the client check the
filesize. Not sure how (well) this works.
My idea:

<body>
[... some code ...]
<script type="text/javascript></script>
<noscript>You have not enabled Javascript! Maybe file uploading will not
work correctly.</noscript>
[... some code ...]
</body>

--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
Aug 24 '06 #12
Rik
Chung Leong wrote:
It's easier to handle this on the client side. The input=file element
should expose the size of the file selected. An element for uploading
multiple files would be nice too. That and a onSubmitProgres s event
for monitoring the upload progress... The lack of innovation really
sucks.

[AOL]
My sentiments exactly.
[/AOL]

Allthough, server-side checking will always have to be done, it's immensely
irritating when:
1. A user waits several minutes to upload something and only then gets the
message the file was to big.
2. Laymen claim you upload doesn't work when they just don't wait untill
it's uploaded. (allthough I usually crudely fix this by placing a message
'uploading..' in the page by js on the onsubmit event.

--
Grtz,

Rik Wasmus
Aug 24 '06 #13
Rik wrote:
Allthough, server-side checking will always have to be done, it's immensely
irritating when:
1. A user waits several minutes to upload something and only then gets the
message the file was to big.
2. Laymen claim you upload doesn't work when they just don't wait untill
it's uploaded. (allthough I usually crudely fix this by placing a message
'uploading..' in the page by js on the onsubmit event.
Often times we run into the opposite problem--users sitting there
waiting for the upload to finish when it has died.

Aug 24 '06 #14
On 23 Aug 2006 15:46:52 -0700, "Chung Leong" <ch***********@ hotmail.comwrot e:
>In theory. I have never seen IE sending an expect 100-continue header.
Maybe Firefox does.
Nope, doesn't.

--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Aug 24 '06 #15
Petr Vileta wrote:
"Schraalhan s Keukenmeester" <fi************ ********@xsfour all.ennelpíse v
diskusním príspevku news:44******** **************@ news.xs4all.nl. ..
>Luke - ea********@gmai l.com wrote:
I believe some choose a javascript solution to have the client check the
filesize. Not sure how (well) this works.

My idea:

<body>
[... some code ...]
<script type="text/javascript></script>
<noscript>You have not enabled Javascript! Maybe file uploading will not
work correctly.</noscript>
[... some code ...]
</body>

As far as I can tell (via Google), it is not even possible with
JavaScript anyway (unless the browser uses and allows Active-X).

--
*************** **************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Everyone's journey should be different,
so that we all are enriched
in new and endless ways
*************** **************
Aug 24 '06 #16
On 22 Aug 2006 14:59:35 -0700, "jeremyz" <je*********@gm ail.comwrote:
>I am not a developer, but I work with several and am posting this for
them. We are trying to determine whether it is possible to check the
size of a file before a user uploads it.

Everything I've read suggests that this is impossible (or at least very
difficult) in PHP, and this makes sense for a server-side language.
What gives me pause, however, is the fact that when a user tries to
upload a file larger than the max file size we allow, an error appears
in our error log immediately -- yet the upload continues.

So somehow PHP must be recognizing that the file is too big well before
it's been uploaded. The question is how -- and how do we make the leap
from that recognition to an immediate halt of the upload?
There's this: http://pdoru.from.ro/

... which is a file upload progress patch for PHP. The demo opens a popup
window that monitors the upload taking place in the first window.

Possibly this could be modified so the second window uses javascript to abort
the upload in the first window? Not sure. Not very nice, but the alternatives
are sparse.

--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Aug 24 '06 #17
Petr Vileta wrote:
>"Schraalhan s Keukenmeester" <fi************ ********@xsfour all.ennelpíse
v diskusním príspevku news:44******** **************@ news.xs4all.nl. ..
>>Luke - ea********@gmai l.com wrote:
I believe some choose a javascript solution to have the client check the
filesize. Not sure how (well) this works.

My idea:

<body>
[... some code ...]
<script type="text/javascript></script>
<noscript>Yo u have not enabled Javascript! Maybe file uploading will not
work correctly.</noscript>
[... some code ...]
</body>

As far as I can tell (via Google), it is not even possible with JavaScript
anyway (unless the browser uses and allows Active-X).

--
*************** **************
Chuck Anderson • Boulder, CO
Yes. Maybe browser put "Content-Length: ???" into HTTP header and PHP can
read it, but not in all cases.
I found this for using ActiveX in MSIE:
http://www.jguru.com/faq/view.jsp?EID=330134

--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
Aug 25 '06 #18
Chung Leong schrieb:
>
It's easier to handle this on the client side. The input=file element
should expose the size of the file selected. An element for uploading
multiple files would be nice too. That and a onSubmitProgres s event for
monitoring the upload progress... The lack of innovation really sucks.
In cases where you don't mind using a Java applet for upload, check out
http://www.radinks.com/upload/.

Provides status bar, choice for HTTP or FTP upload, multiple uploads,
client-side image scaling, is really easy to use, and also not too hard
to implement. The basic version is free, the most sophisticated one
about 40 US$.

I usually don't do advertisement, but this one is one of my favorite
pieces of software...

Markus
Aug 25 '06 #19
jeremyz wrote:
<snip>
What gives me pause, however, is the fact that when a user tries to
upload a file larger than the max file size we allow, an error appears
in our error log immediately -- yet the upload continues.
<snip>

I don't think that will happen if you configure Apache with
LimitRequestBod y
<http://httpd.apache.or g/docs/2.0/mod/core.html#limit requestbody>

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Aug 26 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3933
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give them a caption, storing the caption and filename in a text file. It's a bit buggy when removing the photos and captions from the file, and also in displaying them on the delete page. you can see it in action at www.4am.com.au/gallery/upload.php...
5
5470
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. I want to develop a webpage where people can send attachments that are stored on their local PC.
1
2767
by: BW | last post by:
I am creating an upload/download function for an extranet site. Files will be uploaded to directory based upon the users login and associated project. The function works as long as I use "c:\Temp" as the directory. When I use any other hard coded directory or even Server.MapPath() the upload function fails and returns the error: "Exception has been thrown by the target of an invocation." Once I change the root directory to "c:\Temp",...
4
5902
by: Jim Michaels | last post by:
after a file upload, $_FILES is not populated but $_POST is. what's going on here? $_POST=C $_POST=C $_POST=C $_POST=C:\\www\\jimm\\images\\bg1.jpg $_FILES= $_FILES= $_FILES=
1
4873
by: gryffin | last post by:
im trying to do file extension checking but its not working :( i have the following in the head <script language="JavaScript"> extArray = new Array(".jpg", ".png", ".bmp"); function LimitAttach(form, file) { allowSubmit = false; if (!file) return; while (file.indexOf("\\") != -1)
2
1373
sun1programmer
by: sun1programmer | last post by:
Hi All, I have an HTML File upload control and I want to check the size of uploaded file by the user at the time of uploading. If size exceeds 25MB, then it shows the confirmation message that "File size exceeds 25MB. Do you want to continue anyway". If user clicks on OK button then the file is uploaded else not. I found many solution but all have some limitations. Please try your codes before posting. Thanks & Best of luck.
2
7656
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but don't have any luck is to do a form validation. This script requires the files: db-file-to-disk.asp and _upload.asp. There is a DESCRIPTION field in the db-file-to-disk.asp file, what I want to do is the user has to field out this fied before...
1
5464
by: chrisj | last post by:
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully. In this modified version there are two groups that use this upload script. Members of one group get automatically re-directed after uploading. However, this member group never gets the benefit of knowing if they've uploaded an incorrect file size or incorrect file extension. Members from the second group do see the "exceeds max file...
6
3839
Jacotheron
by: Jacotheron | last post by:
I need a PHP script that can upload music files (mp3). The script is for a home project I have started a while ago. I have a MySQL database of all the music that I have. Other computers on the network should be able to connect to the database and run queries on the database or upload new music that does not yet exist on the database. The uploaded file's name should be in the following format: ARTIST - TITLE.mp3. I have the code to upload images,...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.