[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] File upload
Great lesson thanks.
I have tested the code but i must change the structure because i think (not
really sure) there are nested-if problems
but anymore CR problems.
<head>
<title> Do uploading </title>
</head>
<body>
[tmp write_result][/tmp]
[tmp msg][/tmp]
[tmp contents][/tmp]
[set outfilename]tmp/test_file[/set]
[if type=explicit compare="[value-extended name=uploaded_file
test=isfile]"]
[tmp write_result][value-extended
yes="Success"
no="Failed"
ascii=0
name=uploaded_file
outfile="[scratch outfilename]"
][/tmp]
[else]
[tmp msg]No file upload was specified.[/tmp]
[goto end]
[/else]
[/if]
[if scratch write_result eq "Failed"] <!-- ???...azzo... -->
[tmp msg]File upload failed.[/tmp]
[/if]
[tmp contents][value-extended name=uploaded_file file_contents=1][/tmp]
[if scratch contents][and write_result eq "Success"]
[tmp msg]File upload succeeded.[/tmp]
File contents:<br>----- File begin -----<pre>[scratch
contents]</pre>------ File end ------<br>
[else]
[tmp msg]File upload failed.[/tmp]
Uploaded file is empty or non-existent.
[/else]
[/if]
<br>
write_result=#[scratch write_result]#<br>
msg=#[scratch msg]#<br>
contents=#[scratch contents]#<br>
</body>
</html>
--------------------------------
I test this code in 4 situations
1) blank input
2) input not existent file name
3) not-correct write-dir ex: "mp/test_file" and not "tmp/test_file"
4) all ok
1) OK
2) OK
3) OK but display file contents ( <!-- ???...azzo... -->)
4) OK
----------------------------------------------------------------------------
-------------------------------------
> > 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.
> >
> > 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: