gpt4 book ai didi

php - codeigniter文件上传失败

转载 作者:搜寻专家 更新时间:2023-10-31 20:44:03 24 4
gpt4 key购买 nike

无法上传文件。 $this->upload->do_upload('anonsphoto'); 返回 false。找不到原因。

我以这种方式添加了上传库以自动加载:$autoload['libraries'] = array('upload');

这是我的看法:

<?php
echo form_open_multipart('InterviewController/saveInterview');

$anons_data = array(
'name' => 'anons',
'id' => 'anons_area',
'value' => 'Введите анонс'
);
echo form_textarea($anons_data); ?>

<p>Картинка анонса</p>
<?php
echo form_upload('anonsphoto'); ?>

这是上传文件的 Controller :

public function saveInterview() {
$config['upload_path'] = '/application/upload/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10000';
$config['file_name'] = 'img_' . (string) time();
$this->upload->initialize($config);

$this->upload->do_upload('anonsphoto');
return;
}

上传的文件是 3 kb 大小的 png 文件。我不明白为什么 do_upload 返回 false。有什么想法吗?

最佳答案

文件上传类告诉你所有你需要的。 https://www.codeigniter.com/userguide3/libraries/file_uploading.html

这是一个关键:

$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';

$this->load->library('upload', $config);

// Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:
$this->upload->initialize($config);

“。” (点)表示当前上传路径目录。因此,您的应用无法正常工作,因为您位于不是以(点)开头的根路径上。

您的文件夹应该具有对 0755 的完全权限 (CHMOD)。

这个:

$config['upload_path'] = './uploads/'; 

表示:当前目录和上传目录

或:

$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'].'/application/upload/';

表示:如 Can 所说,您的完整文档 URI 路径和目录 '/application/upload/'

不要忘记输入(点)。在 $_SERVER['DOCUMENT_ROOT']'/application/upload' 之间。

最大大小应以 KiB 值表示:$config['max_size'] = '10000';

希望这有助于理解它的工作原理。

关于php - codeigniter文件上传失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15441349/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com