PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Re: [PHP] MAX_FILE_SIZE not working with file uploads
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: [PHP] MAX_FILE_SIZE not working with file uploads

Réponse
 
LinkBack Outils de la discussion
Vieux 21/09/2007, 06h56   #1 (permalink)
Chris
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] MAX_FILE_SIZE not working with file uploads


> And here is the dump of the $_FILES array (which, notably, reports
> zero as the size):


<snip>

> [error] => 2


And also gives you an error code.

http://www.php.net/manual/en/feature...oad.errors.php

--
Postgresql & php tutorials
http://www.designmagick.com/
  Réponse avec citation
Vieux 23/09/2007, 00h01   #2 (permalink)
Jeff Cohan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] MAX_FILE_SIZE not working with file uploads

Chris wrote:
> [error] => 2
> And also gives you an error code.


Yes, I know and knew that. That's why the upload ultimately fails
(which is okay).

My point is that when a file's size exceeds the MAX_FILE_SIZE value,
I want the browser to (a) detect that it's too large BEFORE
attempting to upload it and (b) report the file size back to the
user. That's what's not happening.
  Réponse avec citation
Vieux 23/09/2007, 01h34   #3 (permalink)
Dan Parry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: [PHP] MAX_FILE_SIZE not working with file uploads

> -----Original Message-----
> From: Jeff Cohan [mailto:jeff@nsiteful.com]
> Sent: 23 September 2007 00:02
> To: php-general@lists.php.net
> Subject: Re: [php] MAX_FILE_SIZE not working with file uploads
>
> Chris wrote:
> > [error] => 2
> > And also gives you an error code.

>
> Yes, I know and knew that. That's why the upload ultimately fails
> (which is okay).
>
> My point is that when a file's size exceeds the MAX_FILE_SIZE value,
> I want the browser to (a) detect that it's too large BEFORE
> attempting to upload


I might be wrong but this would be classed as 'exploitable'... Webservers
should not be allowed to read from or write to clients... Of course there is
ActiveX...

Dan
  Réponse avec citation
Vieux 23/09/2007, 02h00   #4 (permalink)
Dan Parry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: [PHP] MAX_FILE_SIZE not working with file uploads

> -----Original Message-----
> From: Jeff Cohan [mailto:jeff@nsiteful.com]
> Sent: 23 September 2007 02:45
> To: php-general@lists.php.net
> Subject: Re: [php] MAX_FILE_SIZE not working with file uploads
>
>
>
> Dan Parry wrote:
> > I might be wrong but this would be classed as
> > 'exploitable'... Webservers should not be allowed
> > to read from or write to clients... Of course there
> > is ActiveX...

>
> I think we're off the point.
>
> My script is simply interrogating the value of the
> $_FILES[userfile][size] array element. It's coming up as ZERO if it
> exceeds the MAX_FILE_SIZE. That seems odd to me. But maybe that's
> the way it's SUPPOSED to work. That's why I started this thread out
> with "What am I missing?".
>
> Said another way:
>
> It seems that the server had to know the size of the file in order
> to know it exceeded MAX_FILE_SIZE. So how can my script find out the
> size?


I'm not sure it can... The server has to accept the file before it can
process any details on it

The MAX_FILE_SIZE input field is notoriously unreliable... I think if it
returns zero (0) then the PHP limit is reached

Dan
  Réponse avec citation
Vieux 23/09/2007, 02h25   #5 (permalink)
Ray
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] MAX_FILE_SIZE not working with file uploads

On Saturday 22 September 2007 7:44:55 pm Jeff Cohan wrote:
> Dan Parry wrote:
> > I might be wrong but this would be classed as
> > 'exploitable'... Webservers should not be allowed
> > to read from or write to clients... Of course there
> > is ActiveX...

>
> I think we're off the point.
>
> My script is simply interrogating the value of the
> $_FILES[userfile][size] array element. It's coming up as ZERO if it
> exceeds the MAX_FILE_SIZE.


Exactly, no valid file was uploaded. The size of the valid file is therefore
zero.

> That seems odd to me.
> But maybe that's
> the way it's SUPPOSED to work. That's why I started this thread out
> with "What am I missing?".
>
> Said another way:
>
> It seems that the server had to know the size of the file in order
> to know it exceeded MAX_FILE_SIZE. So how can my script find out the
> size?


Can you use Javascript to check file size client side, send data via AJAX then
issue warnings? (Remember the php mantra: "PHP is a server side language" )

As noted in the php.net documentation you quoted, and as mentioned previously,
MAX_FILE_SIZE is a _hint_ to the browser. some browsers just don't take
hints.
Ray
  Réponse avec citation
Vieux 23/09/2007, 02h39   #6 (permalink)
Dan Parry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: [PHP] MAX_FILE_SIZE not working with file uploads

> -----Original Message-----
> From: Ray [mailto:ray@stilltech.net]
> Sent: 23 September 2007 02:25
> To: php-general@lists.php.net
> Subject: Re: [php] MAX_FILE_SIZE not working with file uploads
>
> On Saturday 22 September 2007 7:44:55 pm Jeff Cohan wrote:
> > Dan Parry wrote:
> > > I might be wrong but this would be classed as
> > > 'exploitable'... Webservers should not be allowed
> > > to read from or write to clients... Of course there
> > > is ActiveX...

> >
> > I think we're off the point.
> >
> > My script is simply interrogating the value of the
> > $_FILES[userfile][size] array element. It's coming up as ZERO if it
> > exceeds the MAX_FILE_SIZE.

>
> Exactly, no valid file was uploaded. The size of the valid file is
> therefore
> zero.
>
> > That seems odd to me.
> > But maybe that's
> > the way it's SUPPOSED to work. That's why I started this thread out
> > with "What am I missing?".
> >
> > Said another way:
> >
> > It seems that the server had to know the size of the file in order
> > to know it exceeded MAX_FILE_SIZE. So how can my script find out the
> > size?

>
> Can you use Javascript to check file size client side, send data via
> AJAX then
> issue warnings


This would be the exploitable 'feature' I mentioned... Client-side files
should never be readable

Dan
  Réponse avec citation
Vieux 23/09/2007, 02h44   #7 (permalink)
Jeff Cohan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] MAX_FILE_SIZE not working with file uploads



Dan Parry wrote:
> I might be wrong but this would be classed as
> 'exploitable'... Webservers should not be allowed
> to read from or write to clients... Of course there
> is ActiveX...


I think we're off the point.

My script is simply interrogating the value of the
$_FILES[userfile][size] array element. It's coming up as ZERO if it
exceeds the MAX_FILE_SIZE. That seems odd to me. But maybe that's
the way it's SUPPOSED to work. That's why I started this thread out
with "What am I missing?".

Said another way:

It seems that the server had to know the size of the file in order
to know it exceeded MAX_FILE_SIZE. So how can my script find out the
size?
  Réponse avec citation
Vieux 23/09/2007, 03h24   #8 (permalink)
Ray
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] MAX_FILE_SIZE not working with file uploads

On Saturday 22 September 2007 7:39:01 pm Dan Parry wrote:
> > -----Original Message-----
> > From: Ray [mailto:ray@stilltech.net]
> > Sent: 23 September 2007 02:25
> > To: php-general@lists.php.net
> > Subject: Re: [php] MAX_FILE_SIZE not working with file uploads
> >
> > On Saturday 22 September 2007 7:44:55 pm Jeff Cohan wrote:
> > > Dan Parry wrote:
> > > > I might be wrong but this would be classed as
> > > > 'exploitable'... Webservers should not be allowed
> > > > to read from or write to clients... Of course there
> > > > is ActiveX...
> > >
> > > I think we're off the point.
> > >
> > > My script is simply interrogating the value of the
> > > $_FILES[userfile][size] array element. It's coming up as ZERO if it
> > > exceeds the MAX_FILE_SIZE.

> >
> > Exactly, no valid file was uploaded. The size of the valid file is
> > therefore
> > zero.
> >
> > > That seems odd to me.
> > > But maybe that's
> > > the way it's SUPPOSED to work. That's why I started this thread out
> > > with "What am I missing?".
> > >
> > > Said another way:
> > >
> > > It seems that the server had to know the size of the file in order
> > > to know it exceeded MAX_FILE_SIZE. So how can my script find out the
> > > size?

> >
> > Can you use Javascript to check file size client side, send data via
> > AJAX then
> > issue warnings

>
> This would be the exploitable 'feature' I mentioned... Client-side files
> should never be readable
>
> Dan


If the contents of a file were readable, I would definitely agree with you.
I'm not convinced that the ability to detect the filesize of a file that the
user selected would be exploitable, but it's a moot point as it doesn't work
in javascript. (as someone else pointed out, maybe activeX?)
I'm not a javaScript expert, but I am learning, so I dug out the book, and put
together the following script. (Ugly, insecure, and doesn't really do
anything, but quick and It works, at least on my machine/browser combo)
Select a file, and the page will tell you everything It can about the file. My
machine reports size as zero.
Ray

(Script guaranteed to occupy 0 or more bites of diskspace.)

<html>
<head><TITLE>test</TITLE>
<script type="text/javascript">
function uptest()
{
alert (document.test.fileTest.defaultValue);
alert (document.test.fileTest.form);
alert (document.test.fileTest.name);
alert (document.test.fileTest.readOnly);
alert ('size follows');
alert (document.test.fileTest.size);
alert (document.test.fileTest.type);
alert (document.test.fileTest.value);

}
</script>
</head>
<body>
<form name="test" method="post">
File: <input type="file" onchange="uptest()" name="fileTest"/>
</form>
</body>
</html>
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h38.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15521 seconds with 16 queries