[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] File upload
Marco Mescoli [m.mescoli@omnibit.nu] wrote:
>
> Well i have tested the code and very thanks upload OK.
> I add the tag [value-extended name=uploaded_file file_contents=1] to
> display file content.
> But two problem:
>
> (...snip...)
>
> ----------------------- uploadfile.html ---------------------------------
> <head>
> <title> Do uploading </title>
> </head>
> <body>
> [set outfilename]tmp/test_file[/set]
> [if type=explicit compare="[value-extended name=uploaded_file test=isfile]"]
> [then]
> [tmp result]
> [value-extended
> yes="Success"
> no="Failed"
> ascii=0
> name=uploaded_file
> outfile="[scratch outfilename]"
> ]
> [/tmp]
> [if scratch result] <!-- BEWARE NOT CORRECT -->
> [tmp result]File upload succeeded.[/tmp]
> File contents:<br>
> [value-extended name=uploaded_file file_contents=1]
> [else]
> [tmp result]File upload failed.[/tmp]
> [/else]
> [/if]
> [/then]
> [else]
> [tmp result]No file upload was specified.[/tmp]
> [/else]
> [/if]
> <br><br>
> [scratch result]
> </body>
> </html>
> -------------------------------------------------------------------
>
> 1) [if scratch result eq 'Success'] do not pass even if [scratch result] is
> really equal "Success".
> I try some other type of "if compare" with the same result.
>
The problem is not the [if], but rather the [tmp result]. The way you
modified the example, the 'Success' message would be surrounded with
newlines, which is not what the [if] is being told to expect.
Change this code:
[tmp result]
[value-extended
yes="Success"
no="Failed"
ascii=0
name=uploaded_file
outfile="[scratch outfilename]"
]
[/tmp]
[if scratch result] <!-- BEWARE NOT CORRECT -->
to this:
[tmp result][value-extended
yes="Success"
no="Failed"
ascii=0
name=uploaded_file
outfile="[scratch outfilename]"
][/tmp]
[if scratch result eq 'Success']
>
> 2) If in <input type="file ... > i put a non existent file name [scratch
> result] is equal "Success". May be a problem in [value-extended
> name=uploaded_file test=isfile] ?
>
Perhaps the browser sends a zero-length buffer as the file contents
if a non-existent filename is specified. If this is the case then
you will need a further check. Try changing these lines:
[tmp result]File upload succeeded.[/tmp]
File contents:<br>
[value-extended name=uploaded_file file_contents=1]
to something more like this:
[tmp contents][value-extended
name=uploaded_file
file_contents=1
][/tmp]
[if scratch contents]
[tmp result]File upload succeeded.[/tmp]
File contents:<br>
<pre>[scratch contents]</pre>
[else]
[tmp result]File upload failed.[/tmp]
Uploaded file is empty or non-existent.
[/else]
[/if]
--
_/ _/ _/_/_/_/ _/ _/ _/_/_/ _/ _/
_/_/_/ _/_/ _/ _/ _/ _/_/ _/ K e v i n W a l s h
_/ _/ _/ _/ _/ _/ _/ _/_/ kevin@cursor.biz
_/ _/ _/_/_/_/ _/ _/_/_/ _/ _/