Загрузка файла на сервер

Для загрузки файлов есть следующая схема:
Шаблон:
<form id="fm_upload" class="upload_form" action="/messages/upload" method="post" enctype="multipart/form-data">
    <label for="upl_file">Отправить файл: </label><input id="file" type="file" name="upl_file" />
</form>
 
Вьюха:
def upload_file_view(request):
    if not request.user.is_authenticated(): return render_to_response('index.html')
    if request.method == 'POST':
        upl_file=request.FILES['upl_file']
        if upl_file and upl_file.size < 10485760:
            import os
            upl_root=os.getcwd()+UPLOAD_DIR
            if not os.path.exists(upl_root+request.user.username+'/'):
                os.mkdir(upl_root+request.user.username+'/')
            with open(upl_root+request.user.username+'/'+upl_file.name,'wb') as fh:
                for chunk in upl_file.chunks():
                    fh.write(chunk)
 

Администрирование

Сегодня
Вчера
Эта неделя
Прошлая неделя
Этот месяц
Прошлый месяц
Вся статистика
128
3
222
26686
277
219
26938

IP: 18.188.29.250
Время: 2024-09-19 02:42:29
Счетчик joomla