Hi Attaullah thank you so much.<br>I tried that one too but that file is storing in data.fs which i do not want. i want to store my file to be physically stored. so for that i am trying to write a python script. i have written many script but could not get succeed <br>
#!/usr/local/bin/python<br>&quot;&quot;&quot;This demonstrates a minimal http upload cgi.<br>This allows a user to upload up to three files at once.<br>It is trivial to change the number of files uploaded.<br><br>This script has security risks. A user could attempt to fill<br>
a disk partition with endless uploads. <br>If you have a system open to the public you would obviously want<br>to limit the size and number of files written to the disk.<br><b>&quot;&quot;&quot;<br>import cgi<br>import cgitb; cgitb.enable()<br>
import os, sys<br><br>UPLOAD_DIR = &quot;/home/praveen/Desktop/UPLOAD&quot;<br><br>def save_uploaded_file (form_field, upload_dir):<br>&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;This saves a file uploaded by an HTML form.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The form_field is the name of the file input field from the form.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For example, the following form_field would be &quot;file_1&quot;:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input name=&quot;file_1&quot; type=&quot;file&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The upload_dir is the directory where the file will be written.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If no file was uploaded or if the field does not exist then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this does nothing.<br>&nbsp;&nbsp;&nbsp; &quot;&quot;&quot;<br>&nbsp;&nbsp;&nbsp; <span style="color: rgb(153, 0, 0);">form = cgi.FieldStorage()&nbsp; <i><span style="color: rgb(0, 0, 153);">///when i tried to print form field its returning None</span></i></span><br>
&nbsp;&nbsp;&nbsp; if not form.has_key(form_field): return<br>&nbsp;&nbsp;&nbsp; fileitem = form[form_field]<br>&nbsp;&nbsp;&nbsp; if not fileitem.file: return<br>&nbsp;&nbsp;&nbsp; fout = file (os.path.join(upload_dir, fileitem.filename), &#39;wb&#39;)<br>&nbsp;&nbsp;&nbsp; while 1:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chunk = fileitem.file.read(100000)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not chunk: break<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fout.write (chunk)<br>&nbsp;&nbsp;&nbsp; fout.close()<br><br>save_uploaded_file (&quot;/home/praveen/Desktop/1.html&quot;, UPLOAD_DIR)</b><br><br>this script is not giving me error..<br><br>Is any one know script to save the file physically on the particluar system.. suppose i have file in my Desktop and i have one interface(html page with file text field) which provide to select you file and move to another location /home/praveen/Desktop<br>
<br>Thanks<br><br><div class="gmail_quote">On Fri, Nov 7, 2008 at 4:49 PM, Ataulla S H <span dir="ltr">&lt;<a href="mailto:ataulla@gmail.com">ataulla@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
hi praveen try this<br><br>&nbsp; myrepo = getattr(context,<b>&#39;</b>mydir<b>&#39;<span style="color: rgb(0, 0, 153);"></span></b>)<br>&nbsp; myrepo.manage_addFile(id=id, title=title, file=file)<div><div></div><div class="Wj3C7c">
<br><br><div class="gmail_quote">On Fri, Nov 7, 2008 at 12:31 PM, Praveen Kumar <span dir="ltr">&lt;<a href="mailto:praveen@mahiti.org" target="_blank">praveen@mahiti.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi First of all i would like to thank you for giving me some idea..<br>As Jorgen told i did in same way<br>

Hi Jorgen<br>I created a python script in zope instance to upload multiple files and its working successfully..<br>
but its storing the file inside custom folder as we know context always refer to current location i mean our-instance/custom but when i am giving container[&#39;bin&#39;] its giving me &#39;bin&#39; key error. i want to save that file inside my instance for example<br>


<br>myzope-instance/mydir/<b>&lt;uploaded file&gt;</b> is any one have any idea<br><br><b>REQUEST=context.REQUEST<br>sentFiles = {}<br>for key in context.REQUEST.keys():&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # getting all the ids<br>&nbsp;&nbsp;&nbsp; if key[:5]==&#39;file.&#39; and key[-3:]==&#39;.id&#39;:&nbsp;&nbsp; # we finding id <a href="http://file.XXX.id" target="_blank">file.XXX.id</a><br>


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sentFiles[REQUEST[key]]=&#39;&#39;<br><br>for key in context.REQUEST.keys():<br>&nbsp;&nbsp;&nbsp; if key[:5]==&#39;file.&#39; and key[-3:]!=&#39;.id&#39;:&nbsp;&nbsp;&nbsp; #we&#39;ve got a file<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #found its id and make sure file exists<br>


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if sentFiles.has_key(REQUEST[key+&#39;.id&#39;]) and REQUEST[key].filename:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sentFiles[REQUEST[key+&#39;.id&#39;]]=REQUEST[key]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; del sentFiles[REQUEST[key+&#39;.id&#39;]]&nbsp;&nbsp;&nbsp; #remove keys that dont have files<br>


<br>for k in sentFiles.keys():<br>&nbsp;&nbsp;&nbsp; </b><b style="color: rgb(0, 102, 0);">context.manage_addFile(k,sentFiles[k])</b><br><b>&nbsp;&nbsp;&nbsp; <span style="color: rgb(0, 0, 153);">container[&#39;bin&#39;]</span>.mydir.manage_addFile(k,sentFiles[k])<br>


<br>return str(len(sentFiles)) + &#39; files has been uploaded successfully&#39;</b><div><div></div><div><br><br><br><div class="gmail_quote">On Thu, Nov 6, 2008 at 7:49 PM, Jørgen Jørgensen <span dir="ltr">&lt;<a href="mailto:gardsted@yahoo.com" target="_blank">gardsted@yahoo.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


  
  

<div bgcolor="#ffffff" text="#000000">
Hello Praween Kumar - <br>
I would make a pythonscript on the zope like
&#39;locahost:8080/starinstance/myscript&#39;, taking 3 parameters, id, title
and file.<br>
remember to give it manager proxy rights (proxy in top of python script
edit screen, chose manager)<br>
script should be something like:<br>
&quot;&quot;&quot;<br>
container[&#39;bin&#39;].manage_addFile(id=id, title=title, file=file)<br>
&quot;&quot;&quot;<br>
I havent tested, sorry;-), but at least the direction should be
something like this.<br>
then change addfileurl to:<br>
<br>
<b>addfileurl=&#39;<a href="http://localhost:8080/starinstance/bin/manage_addFile" target="_blank">http://localhost:8080/starinstance/myscript</a>&#39;</b><br>
<br>
kind regards jorgen / denmark<br>
<br>
<br>
Praveen Kumar wrote:
<blockquote type="cite">Dear all,<div><br>
I want to save the file on filebased system. i am using urllib<br>
  <br></div><div><div></div><div>
here i tried with this code<br>
  <br>
  <b>import urllib<br>
  <br>
# fill these in<br>
user=&#39;admin&#39;<br>
password=&#39;admin1&#39;<br>
addfileurl=&#39;<a href="http://localhost:8080/starinstance/bin/manage_addFile" target="_blank">http://localhost:8080/starinstance/bin/manage_addFile</a>&#39;<br>
useragent=&quot;upload.py/0.1&quot;<br>
filename=&#39;/home/praveen/Desktop/text.jpeg&#39;<br>
filetitle=&#39;a nice test picture&#39;<br>
  <br>
class <span style="color: rgb(0, 102, 0);">MyUrlOpener</span>(<span style="color: rgb(0, 0, 153);">urllib.FancyURLopener</span>):<br>
&nbsp; &nbsp;def prompt_user_passwd(self, host, realm):<br>
&nbsp; &nbsp; &nbsp; &nbsp; return (user,password)<br>
&nbsp; &nbsp;def __init__(self, *args):<br>
&nbsp; &nbsp; &nbsp; self.version = useragent<br>
&nbsp; &nbsp; &nbsp; <span style="color: rgb(0, 102, 0);">urllib.FancyURLopener.__init__(self,
*args)</span><br>
  <br>
def main():<br>
&nbsp; &nbsp; &nbsp; &nbsp;# use authentication and set the user agent<br>
&nbsp; &nbsp; &nbsp; &nbsp;urllib._urlopener = MyUrlOpener()<br>
  <br>
&nbsp; &nbsp; &nbsp; &nbsp;# read the contents of filename into filebody<br>
&nbsp; &nbsp; &nbsp; &nbsp;f=open(filename)<br>
&nbsp; &nbsp; &nbsp; &nbsp;filebody=f.read()<br>
&nbsp; &nbsp; &nbsp; &nbsp;f.close<br>
  <br>
&nbsp; &nbsp; &nbsp; &nbsp;# urlencode the id, title and file<br>
&nbsp; &nbsp; &nbsp; &nbsp;params = urllib.urlencode({&#39;id&#39;: filename,<br>
&nbsp; &nbsp; &nbsp; &nbsp;&#39;title&#39;:filetitle,<br>
&nbsp; &nbsp; &nbsp; &nbsp;&#39;file&#39;:filebody})<br>
  <br>
&nbsp; &nbsp; &nbsp; &nbsp;# send the file to zope<br>
&nbsp; &nbsp; &nbsp; &nbsp;f=urllib.urlopen(addfileurl, params)<br>
  <br>
if __name__ == &#39;__main__&#39;:<br>
&nbsp; &nbsp;main()</b><br>
  <br>
when i compile this file with simple python demo.py it gives me error<br>
Traceback (most recent call last):<br>
&nbsp; File &quot;demo.py&quot;, line 36, in ?<br>
&nbsp;&nbsp;&nbsp; main()<br>
&nbsp; File &quot;demo.py&quot;, line 33, in main<br>
&nbsp;&nbsp;&nbsp; f=urllib.urlopen(addfileurl, params)<br>
&nbsp; File &quot;/usr/lib/python2.4/urllib.py&quot;, line 84, in urlopen<br>
&nbsp;&nbsp;&nbsp; return opener.open(url, data)<br>
&nbsp; File &quot;/usr/lib/python2.4/urllib.py&quot;, line 192, in open<br>
&nbsp;&nbsp;&nbsp; return getattr(self, name)(url, data)<br>
&nbsp; File &quot;/usr/lib/python2.4/urllib.py&quot;, line 272, in open_http<br>
&nbsp;&nbsp;&nbsp; import httplib<br>
&nbsp; File &quot;/usr/lib/python2.4/httplib.py&quot;, line 70, in ?<br>
&nbsp;&nbsp;&nbsp; import mimetools<br>
&nbsp; File &quot;/usr/lib/python2.4/mimetools.py&quot;, line 6, in ?<br>
&nbsp;&nbsp;&nbsp; import tempfile<br>
&nbsp; File &quot;/usr/lib/python2.4/tempfile.py&quot;, line 33, in ?<br>
&nbsp;&nbsp;&nbsp; from random import Random as _Random<br>
&nbsp; File &quot;/usr/lib/python2.4/random.py&quot;, line 43, in ?<br>
&nbsp;&nbsp;&nbsp; from math import log as _log, exp as _exp, pi as _pi, e as _e<br></div></div><div>
ImportError: /usr/lib/python2.4/lib-dynload/math.so: undefined symbol:
PyFPE_jbuf<br>
  <br></div><div><div></div><div>
so i compiled with this command <b style="color: rgb(153, 0, 0);">python2.4
demo.py</b> it does not give any error<br>
but it does not give me output to when i check my directory where i am
trying to save my jpeg file <b><a href="http://localhost:8080/starinstance/bin/manage_addFile" target="_blank">http://localhost:8080/starinstance/bin/manage_addFile</a>
  </b>there i do not find that file it means it is not able to store
that file.<br>
  <br>
i do not know what i am trying to do..could any one please give me idea
how may i store the file on file system.<br>
i created a html page<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;form name=&quot;demo&quot; method=&quot;post&quot; ENCTYPE=&quot;multipart/form-data&quot;
ACTION=&quot;&quot;&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;fieldset style=&quot;width:20%&quot;&gt;<br>
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Id:&lt;input type=&quot;text&quot; name=&quot;title&quot;
id=&quot;title&quot;/&gt;&lt;br&gt;&lt;br&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name:&lt;input type=&quot;text&quot; name=&quot;name&quot;
id=&quot;name&quot;/&gt;&lt;br&gt;&lt;br&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Keywords:&lt;input type=&quot;text&quot; name=&quot;keywords&quot;
id=&quot;keywords&quot;/&gt;&lt;br&gt;&lt;br&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type=&quot;file&quot; name=&quot;upload&quot;
id=&quot;upload&quot;/&gt;&lt;br&gt;&lt;br&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Save&quot;
id=&quot;submit&quot;/&gt;&lt;br&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/fieldset&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp; &lt;/form&gt;<br>
once if user select any file it should store to specific location <b><a href="http://localhost:8080/starinstance/bin/manage_addFile" target="_blank">http://localhost:8080/starinstance/bin/manage_addFile</a><br>
  <br>
  </b>Any suggestion will be appreciable<br>
  <br>
Thanks.<br>
-- <br>
Praveen Kumar<br>
Software Engineer<br>
Mahiti Infotech Pvt. Ltd.<br>
# 33-34, Hennur Cross<br>
Hennur Main Road<br>
Bangalore, India - 560043<br>
Mobile: &nbsp;+91 9343297314<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +91 9739854134<br>
  <a href="http://www.mahiti.org" target="_blank">http://www.mahiti.org</a><br>
  <br>
  </div></div><pre><hr size="4" width="90%"><div>
_______________________________________________
BangPypers mailing list
<a href="mailto:BangPypers@python.org" target="_blank">BangPypers@python.org</a>
<a href="http://mail.python.org/mailman/listinfo/bangpypers" target="_blank">http://mail.python.org/mailman/listinfo/bangpypers</a>
  </div></pre>
</blockquote>
</div>
<p> 

      </p><br>_______________________________________________<br>
BangPypers mailing list<br>
<a href="mailto:BangPypers@python.org" target="_blank">BangPypers@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/bangpypers" target="_blank">http://mail.python.org/mailman/listinfo/bangpypers</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Praveen Kumar<br>Software Engineer<br>Mahiti Infotech Pvt. Ltd.<br># 33-34, Hennur Cross<br>Hennur Main Road<br>Bangalore, India - 560043<br>Mobile: &nbsp;+91 9343297314<br>


 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +91 9739854134<br><a href="http://www.mahiti.org" target="_blank">http://www.mahiti.org</a><br>
</div></div><br>_______________________________________________<br>
BangPypers mailing list<br>
<a href="mailto:BangPypers@python.org" target="_blank">BangPypers@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/bangpypers" target="_blank">http://mail.python.org/mailman/listinfo/bangpypers</a><br>
<br></blockquote></div><br><br clear="all"><br></div></div><font color="#888888">-- <br>Ataulla SH<br><br>web:<a href="http://www.kring.com" target="_blank">www.kring.com</a><br>personal blog:<a href="http://www.ataulla.objectis.net" target="_blank">www.ataulla.objectis.net</a><br>
KRING Technologies India Pvt. Ltd.<br>
1st Floor, Tower B, Infinity Towers, DLF II, Gurgaon-122 002<br>
</font><br>_______________________________________________<br>
BangPypers mailing list<br>
<a href="mailto:BangPypers@python.org">BangPypers@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/bangpypers" target="_blank">http://mail.python.org/mailman/listinfo/bangpypers</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Praveen Kumar<br>Software Engineer<br>Mahiti Infotech Pvt. Ltd.<br># 33-34, Hennur Cross<br>Hennur Main Road<br>Bangalore, India - 560043<br>Mobile: &nbsp;+91 9343297314<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +91 9739854134<br><a href="http://www.mahiti.org">http://www.mahiti.org</a><br>