CurveGamma
CurveGamma

Reputation: 4559

Get Path of Uploaded File using Python

Is it possible to get the full path of the file on the user's computer being uploaded to my site?

Using os.path.abspath(fileitem.filename) simply gets me the address of where my script is executing from on my shared hosting server.

FYI: fileitem = form['file'] and form = cgi.FieldStorage()

Upvotes: 0

Views: 2313

Answers (2)

Krzysztof Kotowicz
Krzysztof Kotowicz

Reputation: 143

To complete the answer - IE <= 7 used to send full file path instead of filename only, but IE 8 changed the default setting and sends only file names for privacy reasons.

Even if client did send the full file path, many web-based solutions (e.g PHP, Django) will strip the path and leave only filename, protecting the application against path traversal attacks. Python's cgi library is not one of them though.

So - yes, you're able to get the full file path with Python cgi, but only if client sent it using IE <= 7.

Upvotes: 0

Michael Mrozek
Michael Mrozek

Reputation: 175595

No, that information isn't sent by the user, so it's not available on your end

Upvotes: 5

Related Questions