我使用Django框架构建了一个网站,其中之一是处理用户上传的图像并将其保存在文件夹中以供下载,但是遇到错误([Errno 13]权限被拒绝:After .png') 。我使用(python3 manage。py runserver),它可以工作,但是在与Apache 2一起部署时不起作用。
我知道这是Ubuntu权限的问题,但修改文件的权限后无法解决。 我希望有人能给我一些建议。确实非常感谢您。
我的代码:
<?php
if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
/**
*
* NEOU CMS v4 CI Edition
* @copyright (c) 2018, Alexander Fagard
* @requires PHP version >= 5.6
*
* You cannot redistribute this document without written permission from the author
*
*/
class Update extends MY_Backend {
static $perm = ['admin_only' => true];
public function __construct() {
parent::__construct();
$this->lang->load('core_update');
$this->load->model('backend/core_update_model', 'update');
}
public function index() {
$this->tpl->head($this->lang->line('update_heading'));
$this->tpl->body();
$this->output->append_output($this->messages->display());
$data = array(
'is_local' => $this->localization->is_local(),
'previous_exist' => $this->update->previous_exists()
);
$this->parser->parse('backend/core_update', $data);
$this->tpl->footer();
}
public function restore() {
try {
$this->update->restore_previous();
rmdir_recursive($this->update->updates_folder);
$this->messages->success($this->lang->line('update_previous_restored'));
} catch (Exception $e) {
$this->messages->error($e->getMessage());
} finally {
redirect(CMS_DIR_NAME . '/update');
}
}
public function apply() {
$this->load->helper('byte_helper');
try {
$this->update->mk_update_dir();
$config['upload_path'] = $this->update->updates_folder;
$config['overwrite'] = true;
$config['allowed_types'] = 'zip';
$config['max_size'] = convert_bytes_to_type(file_upload_max_size(), 'KB');
$config['file_ext_tolower'] = true;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('update')) {
throw new Exception($this->upload->display_errors('', ''));
}
$data = $this->upload->data();
$this->update->apply_update($data['full_path']);
$this->messages->success($this->lang->line('update_applied'));
} catch (Exception $e) {
$this->messages->error($e->getMessage());
} finally {
redirect(CMS_DIR_NAME . '/update');
}
}
public function create() {
if (!$this->localization->is_local()) {
show_error($this->lang->line('update_localhost'), 500);
}
try {
$this->update->create_update();
$this->messages->success(sprintf($this->lang->line('update_created'), $this->update->files_processed));
} catch (Exception $e) {
$this->messages->error($e->getMessage());
} finally {
redirect(CMS_DIR_NAME . '/update');
}
}
}
错误信息
PermissionError at /Text_embed/embedding_info/ [Errno 13] Permission denied: 'After.png'
答案 0 :(得分:0)
好吧,我解决了这个问题,我更改了图像的根部并且可以正常工作!
之前:
Image.fromarray(im).save('After.png') file=open('After.png','rb')
之后:
Image.fromarray(im).save('/home/Lenote/After.png') file=open('/home/Lenote/After.png','rb')
因为当我使用python3 manage.py runserver
save('After.png')
时将创建图像为/home/Lenote/After.png.
,但是当我使用apache2时,可能会在未经许可的情况下在/etc/apache2/....
中创建图像。
谢谢大家。特别要感谢Micheal J Roberts:)。