This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to set CGI upload path?
#1
We set the path to /tmp/, but found upload file in 
/tmp/systemd-private-efff6f88187e49ac8e2197edc20f6ad5-apache2.service-QuWwdx/tmp/.

python code
Code:
open('/tmp/' + fn, 'wb').write(fileitem.file.read())
How to set the correct path for upload file? Huh Huh Huh

/var/www/html/hello_savefile.html
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Aaron Test</title>
</head>
<body>
<form enctype="multipart/form-data"
                    action="/cgi-bin/save_file.py" method="post">
  <p><input type="file" name="filename" /></p>
  <p><input type="submit" value="Upload" /></p>
  </form>
</body>
</html>

/var/www/cgi-bin/save_file.py
Code:
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os, cgi
import cgitb; cgitb.enable()

fs = cgi.FieldStorage()
fileitem = fs['filename']      

# Test if the file was uploaded
if fileitem.filename:
  fn = os.path.basename(fileitem.filename)
  open('/tmp/'+ fn, 'wb').write(fileitem.file.read())
  message = 'The file "' + fn + '" was uploaded successfully'
else:
  message = 'No file was uploaded'

print """\
Content-Type: text/html\n
<html>
<head>
<meta charset="utf-8">
<title>Aaron Test</title>
</head>
<body>
  <p>%s</p>
</body>
</html>
""" % (message,)
Reply
#2
I found a way to set the path is cgi-bin/upload

python code
Code:
open('upload/' + fn, 'wb').write(fileitem.file.read())

Code:
$sudo mkdir /var/www/cgi-bin/upload
$sudo chmod 777 /var/www/cgi-bin/upload
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)