>> Do you mean writing code to reply to the user clicking the browse button in
>> the 'open outline' dialog in order to load an OPML outline from his local
>> workstation ?
"Dirk Wintergruen" <dwinter@...> wrote:
> yes
Ok, I do not know how Zope processes INPUT type="file" HTML for fields in
http POST requests, but here is how we process it in iJot's PHP back-end:
<body>
<script type="text/javascript">
<?php
$err = '';
define ('MAXSIZE', 1024 * 1024);
// max file size is 1 Mb.
if (! $_FILES['file']['error']) {
// check for errors, 0 = no error
if ($_FILES['file']['tmp_name']) {
// check file existence
$name = $_FILES['file']['name'];
$type = $_FILES['file']['type'];
$size = $_FILES['file']['size'];
if ($size) {
// check file existence
if ($size <= MAXSIZE) {
// check file size
if (preg_match ('/opml$/', $type) || preg_match
('/\.opml$/', $name)) {
$tmpUrl = "/tmp/imports/$name";
// url to temporary file
$tmp = realpath ($_SERVER['DOCUMENT_ROOT']) .
$tmpUrl; // path to temporary file
if (! copy ($_FILES['file']['tmp_name'], $tmp)) {
$err .= "Unable to retrieve local outline.";
} else {
echo "parent.loadXMLDoc (\"$tmpUrl\");\n";
}
} else {
// or error message
$err = "$name does not appear to be an OPML
outline.";
}
} else {
$err = 'maximum allowed size for outline files is ' .
MAXSIZE . ' bytes.';
}
} else {
$err = 'file not found. please use the browse button to
select an outline.';
}
} else {
$err = 'file not found. please use the browse button to select
an outline.';
}
} else {
// some error was detected
switch ($_FILES['file']['error']) {
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
$err = 'maximum allowed size for outline files is ' .
MAXSIZE . ' bytes.';
break;
case UPLOAD_ERR_PARTIAL:
$err = 'outline file was only partially uploaded.';
break;
case ERR_NO_FILE:
$err = 'Please supply an outline file for upload using the
browse button.';
break;
default:
$err = 'upload failed.';
break;
}
}
if ($err) {
echo "parent.document.getElementById ('titleDiv').innerHTML =
'Error: $err';\n"; // format msg
as javascript
}
?>
</script>
</body>
The open dialog form is posted using a hidden IFRAME of the webOutliner
window as target.
The PHP response to the POST request generates Javascript code which
executes in that hidden IFRAME depending on how the upload goes...
If all goes well, we call webOutliner's loadXMLDoc function, passing the url
of the uploaded OPML doc, stored in a temporary location.
If not, we display an error message.
HTH
Marc
-----------
Marc Barrot
Precision IT Management, Inc
marc@...