[Zope] file upload formular

Simon Brun simon@tac.ch
Thu, 13 Jun 2002 20:40:54 +0200


hi

Thank you all for answering me :) Here is a test script which one you can upload
files through a html formular and they will  be added to a choosen folder.

The code looks like this (the var "upload_dir" have to exist. I access the file
like this: http://myintranet.com/addFile?upload_dir=CURRENT_FOLDER):

<dtml-var standard_html_header>
<dtml-if action>
  <dtml-with "new_intranet">
    <dtml-with "_[upload_dir]">
      <dtml-call "_[content_dir].manage_addFile(id=content_id,
title=content_title, file=content_file)">
      <dtml-call "_[content_dir]._[content_id].manage_addProperty('author',
worker, 'string')">
      <dtml-call "_[content_dir]._[content_id].manage_addProperty('comments',
comment, 'line')">
    </dtml-with>
  </dtml-with>

<h3>Successfully uploaded</h3>
The file named <b><dtml-var content_id></b> with the title <b><dtml-var
content_title></b> 
was uploaded successfully into folder 
<b><dtml-var content_dir></b>!
<br>
<br>
<a href="<dtml-var content_dir>">back</a>

<dtml-else>
  
<h3>File upload</h3>

<form action="addFile" method="post" enctype="multipart/form-data">
  <input type="hidden" name="action" value="1">
  <input type="hidden" name="upload_dir" value="<dtml-var upload_dir>">
  
  <table border="0">
    <tr>
      <th align="left">Choose the directory</th>
    </tr>
  
	<dtml-with "new_intranet">
   	 <dtml-with "_[upload_dir]">
   	   <dtml-in "objectIds('Folder')">
        	<dtml-let folder=sequence-item>
	          <tr><td><input type="radio" name="content_dir" value="<dtml-var
folder>">
                  <dtml-var folder></td></tr>
	        </dtml-let>
	      </dtml-in>
	 </dtml-with>
	</dtml-with>
    <tr>
      <th align="left"><br>Responsible / author</th>
    </tr>
    <tr>
      <td><input type="text" name="worker"></td>
    </tr>
    <tr>
      <th align="left"><br>Choose the file name</th>
    </tr>
    <tr>
      <td><input type="text" name="content_id"></td>
    </tr>
    <tr>
      <th align="left"><br>Choose a title (will be displayed as link)</th>
    </tr>
    <tr>
      <td><input type="text" name="content_title"></td>
    </tr>
    <tr>
      <th align="left"><br>Choose the file</th>
    </tr>
    <tr>
      <td><input type="file" name="content_file"></td>
    </tr>
    <tr>
      <th align="left"><br>Comments</th>
    </tr>
    <tr>
      <td><textarea name="comment" cols="50" rows="5"></textarea></td>
    </tr>
    <tr>
      <td><br><input type="submit" value="Upload File"></td>
    </tr>
  </table>
</form>
</dtml-if>
<dtml-var standard_html_footer>

The code works fine, when I comment out the "manage_addProperty"-Stuff. I can
add properties to files without a problem, but not to the file I just uploaded.
When I try, I get a "Authorization required" window! Can someone explain me why
and how I can fix it?

regards
simon