Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 32 additions & 25 deletions filemanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,17 @@ def handle_form(self, form, files):
for chunk in f.chunks():
dest.write(chunk)
f.close()
mimetype = magic.from_file(filepath, mime=True)
guessed_exts = mimetypes.guess_all_extensions(mimetype)
guessed_exts = [ext[1:] for ext in guessed_exts]
common = [ext for ext in guessed_exts if ext in self.extensions]
if not common:
os.remove(filepath)
messages.append(
"File type not allowed : "
+ f.name
)
if self.extensions is not None:
mimetype = magic.from_file(filepath, mime=True)
guessed_exts = mimetypes.guess_all_extensions(mimetype)
guessed_exts = [ext[1:] for ext in guessed_exts]
common = [ext for ext in guessed_exts if ext in self.extensions]
if not common:
os.remove(filepath)
messages.append(
"File type not allowed : "
+ f.name
)
if len(messages) == 0:
messages.append('All files uploaded successfully')
elif action == 'add':
Expand Down Expand Up @@ -340,22 +341,28 @@ def handle_form(self, form, files):
+ os.path.basename(path)
)
zip_ref = zipfile.ZipFile(filename, 'r')
# zip_ref.extractall(self.basepath + self.current_path)
directory = self.basepath + self.current_path
for file in zip_ref.namelist():
if file.endswith(tuple(self.extensions)):
zip_ref.extract(file, directory)
mimetype = magic.from_file(directory + file, mime=True)
print directory + file
guessed_exts = mimetypes.guess_all_extensions(mimetype)
guessed_exts = [ext[1:] for ext in guessed_exts]
common = [ext for ext in guessed_exts if ext in self.extensions]
if not common:
os.remove(directory+file)
if self.extensions is None:
zip_ref.extractall(self.basepath + self.current_path)
else:
directory = self.basepath + self.current_path
for file in zip_ref.namelist():
if file.endswith(tuple(self.extensions)):
zip_ref.extract(file, directory)
mimetype = magic.from_file(directory + file, mime=True)
guessed_exts = mimetypes.guess_all_extensions(mimetype)
guessed_exts = [ext[1:] for ext in guessed_exts]
common = [ext for ext in guessed_exts if ext in self.extensions]
if not common:
os.remove(directory+file)
messages.append(
"File in the zip is not allowed : "
+ file
)
else:
messages.append(
"File in the zip is not allowed : "
+ file
)
"File in the zip is not allowed : "
+ file
)
zip_ref.close()
except Exception as e:
print e
Expand Down