[line 67]
FILE Form Field Class (for uploading files to the server).
example tag: <input name="fieldname" type="file" size="20">
what's special about this tag?
- $valueDefault => there is no, no, no way to give the form field a default value.
forget it, even js does not help. believe me.
if you could set a default value, you could auto-submit
a hidden form and steal files from the users computer.
so valueDefault is the value (path) we currently have. and that's
what we show (next to the field).
- $valueReceived => the original file/path we got from the browser, that is
where the file was on the clients machine.
- $valueDisplay => same as $valueReceived, but makes no sense to use/display it.
- $valueInternal => same as $valueReceived, but makes no sense to use it.
- keep file => if a file has been uploaded, but the form has not been
completely accepted (errors in other fields) we keep
the temp file on the server. the user does not need
to resubmit the file, but he may do that (to overwrite).
validating: all validation rules etc are for the given file name. for example a maxLength of 20 here means that the user file (the fullpath on the users machine, as submitted) may not be longer than 20 characters. if it makes sense to use these validators here is up to you. if you want to check the file size (bits) then use the special vars of this class.
WARNING: until things get stable here this class has to be considered experimental. there are things that could go wrong with the complexity of the form classes (multilevel forms, different values like valueDisplay, etc). 2003-01-07 --andrej please don't use the explode functionality here [yet], things would go wrong.
general file upload issues:
1) Another issue with large file sizes. Make sure you set the ammount of
memory to be higher in the PHP.ini file if you want to transfer files over
8MB(default) or it won't transfer, you'll get a "page cannot be displayed".
2) don't put an underscore _ in the file form field name. it won't work on mac and maybe win98.
3) If the upload file size exceeds MAX_FILE_SIZE, $userfile will be set to 'none'.
4) The http proxy "Squid" limits PUT/POST requests to 1 MB per default!
see http://squid.visolve.com/squid24s1/tuning.htm#request_body_max_size
dependencies: Bs_FormFieldTxt, Bs_FileSystem
reading: http://www.php.net/manual/en/features.file-upload.php
Tags:
$allowedTypes =
[line 80]
the file types we accept.
by default anything goes. array('doc', 'xls') means all we accept is .doc and .xml files, case does not matter. int 1 means we only accept web images (jpg, jpeg, gif, png)
Tags:
$diskStorage = NULL
[line 151]
hash with the keys:
'path' //'name' //'extension'
Tags:
$fileInfo = 0
[line 139]
array with information about the uploaded file.
gets set in $this->_keepUploadedFile().
has these keys:
'origFullPath' => the file full path (or name only, depending on browser) as it was on the clients machine. very interesting :-)
'tmpFullPath' => the full path to the temporary file.
'mimeType' => like 'image/gif', 'text/html' etc. if provided by the browser.
'sizeBytes' => the file size in bytes
'errorCode' => int, 0 = everything ok, >0 = not ok.
read http://www.php.net/manual/en/features.file-upload.errors.php
even if the user has an older version than php4.2 we set this var.
'errorText' => textual error message. empty by default.
'extension' => the file extension, eg 'gif' for a file uploaded as '/dir/foo.xy.gif'
if you wanna know if a valid file was submitted then always check 'errorCode' and nothing else.
0 => everything ok, file uploaded correctly.
ERROR (not 0, means no file recieved)
1 => The uploaded file exceeds the upload_max_filesize directive in php.ini.
2 => The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form.
3 => The uploaded file was only partially uploaded.
4 => No file was uploaded. (that may be ok if there is no need to upload!)
5 => Uploaded file size 0 bytes (undocumented php constant)
9 => unknown error (in pre-php-4.2 versions, that means a file upload was attempted but failed. like error code 1-3 or 5.)
99 => unknown system problem (could not rename temp file).
treat every other number > 0 as "something failed, but dunno what".
Tags:
$fileSizeUpdateIni = TRUE
[line 103]
if the maxFileSize specified here is larger than the value specified in the ini file then we'll automatically update the ini (for this request, right?).
Tags:
$maxFileSize =
[line 87]
max file size in bytes, if any.
Tags:
$minFileSize =
[line 94]
min file size in bytes, if any.
Tags:
$showCurrentFile = 1
[line 171]
should there be a note about the currently saved file?
1 = as text (default)
2 = as text with link to file in new window
3 = as text with link to file in popup (not coded yet, falls back to option 2)
4 = as text, and show file directly in browser if it is an image (gif, jpg or png),
otherwise put a link to target "_blank" just as option 2. only recommended for small images.
todo: check that it's an image. maybe check image size and width/height, and set some limit.
if over limit then fall back to link.
Tags:
$showCurrentFilePrefixPath = ''
[line 190]
if var $showCurrentFile is set to 2-4 then we need to know the full path of the file.
we may not have that information in $valueDefault, it most probably is a subpath. anyway, you can give a prefix path here. note that if your file is not located in the webroot and you still want to link to it, you can give a prefix path like "/showFile.php?file=" which will take the file name as param, and spit it out.
examples: $showCurrentFilePrefixPath = '/foo/'; $showCurrentFilePrefixPath = 'http://www.host.com/foo/'; $showCurrentFilePrefixPath = '/showFile.php?file=';
Tags: